S = input()
dic = {s : S.count(s) for s in set(S)}
memo = [[0 for i in range(len(S)-j)] for j in range(len(S))]
word = [[set() for i in range(len(S)-j)] for j in range(len(S))]

for i in range(len(S)):
    for j in range(len(S)-i):
        if i == 0:
            memo[j][i] = 1
            word[j][i].add(S[i])
        else:
            w = word[j][i-1] ^ {S[i + j]}
            word[j][i] = w
            if len(w) < 2:
                memo[j][i] = 1
            else:
                memo[j][i] = min(memo[j][k] + memo[j+k+1][i-k-1] for k in range(i))

print(memo[0][len(S)-1])

            
    