n = int(input())
ll = input()
D = [[0]*n, [1] * n]
for d in range(2, n + 1):
    D.append([
        min(D[k][i] + D[d - k][i + k] for k in range(1, d))
        for i in range(n-d+1)
    ])
    for i in range(n-d+1):
        if ll[i] == ll[i + d - 1]: 
            D[d][i] = min(D[d][i], D[d - 2][i + 1])
print(D[n][0])
