#include <bits/stdc++.h>
using namespace std;
const int N=50+5;
const int inf=0x3f3f3f3f;
int n;
char s[N];
int f[N][N];
int dp(int l,int r){
if (l==r)return f[l][r]=1;
if (f[l][r]!=inf)return f[l][r];
if (s[l]==s[r])f[l][r]=min(f[l][r],min(dp(l+1,r),dp(l,r-1)));
else{
for (int k=l;k<=r-1;k++)f[l][r]=min(f[l][r],dp(l,k)+dp(k+1,r));
}
return f[l][r];
}
int main(){
freopen ("tuse.in","r",stdin);
freopen ("tuse.out","w",stdout);
scanf("%s",s+1);
n=strlen(s+1);
memset(f,0x3f,sizeof(f));
printf("%d\n",dp(1,n));
return 0;
}