N = int(eval(input()))

S = eval(input())



x = 0

x_max = 0



for i in range(N):

    if S[i] == "I":

        x += 1

    else:

        x -= 1

    if x > x_max:

        x_max = x



print(x_max)

N = int(eval(input()))

S = eval(input())



x = 0

x_max = 0



for i in range(N):

    if S[i] == "I":

        x += 1

    else:

        x -= 1

    x_max = max(x, x_max)



print(x_max)

N = int(eval(input()))
S = eval(input())
x = 0
x_max = 0
for i in range(N):
    if S[i] == "I":
        x += 1
    else:
        x -= 1
    if x > x_max:
        x_max = x
print(x_max)

N = int(eval(input()))
S = eval(input())
x = 0
x_max = 0
for i in range(N):
    if S[i] == "I":
        x += 1
    else:
        x -= 1
    x_max = max(x, x_max)
print(x_max)

-    if x > x_max: -        x_max = x +    x_max = max(x, x_max)