#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 1e6 + 10;
char s[N];
vector<int> g[N];
int d[N], vis[N], A[N];
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = (1); i < (n); ++i) {
    if (s[i] != s[i + 1]) {
      g[0].push_back(i);
      g[0].push_back(i + 1);
    } else if (s[i] == s[i + 1]) {
      g[i].push_back(i + 1);
      g[i + 1].push_back(i);
    }
  }
  queue<int> Q;
  Q.push(0);
  vis[0] = 1;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (auto y : g[x])
      if (!vis[y]) {
        d[y] = d[x] + 1;
        vis[y] = 1;
        Q.push(y);
      }
  }
  for (int i = (0); i < (n + 1); ++i) A[i] = i;
  sort(A, A + n + 1, [](int a, int b) { return d[a] > d[b]; });
  int ans = -1;
  for (int i = (0); i < (n); ++i)
    if (d[A[i]] == d[A[i + 1]] && s[A[i]] != s[A[i + 1]]) {
      ans = d[A[i]];
      break;
    }
  printf("%d\n", ans);
  return 0;
}
