n = int(eval(input()))

S = eval(input())

x = 0

ans = 0

for s in S:

    if s=='I':

        x += 1

    else:

        x -= 1

    ans = max(x,ans)

print(ans)
n = int(eval(input()))

S = eval(input())

x = 0

ans = 0

for s in S:

    if s=='I':

        x += 1

        ans = max(x,ans)

    else:

        x -= 1

print(ans)
n = int(eval(input()))
S = eval(input())
x = 0
ans = 0
for s in S:
    if s == "I":
        x += 1
    else:
        x -= 1
    ans = max(x, ans)
print(ans)

n = int(eval(input()))
S = eval(input())
x = 0
ans = 0
for s in S:
    if s == "I":
        x += 1
        ans = max(x, ans)
    else:
        x -= 1
print(ans)

+        ans = max(x, ans) -    ans = max(x, ans)