#include <bits/stdc++.h>
const double PI = 3.14159265358979323846;
using namespace std;
const double EPS = 1e-9;
const long long INF = 10e17;
std::istream &operator>>(std::istream &in, set<int> &o) {
  long long a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }
bool is_kaibun(string &s, int i, int j) {
  set<char> st;
  for (int k = i; k <= j; k++) {
    if (contain(st, s[k]))
      st.erase(s[k]);
    else
      st.insert(s[k]);
  }
  return st.size() <= 1;
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> dp(n + 1, -1);
  dp[0] = 0;
  auto set = [&](int i, int k) {
    if (dp[i] == -1)
      dp[i] = k;
    else
      dp[i] = min(dp[i], k);
  };
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (is_kaibun(s, i, j)) set(j + 1, dp[i] + 1);
    }
  }
  cout << dp[n] << endl;
}
