import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/*
 public class _909D {

 }

 */
public class _909D {
  class group {
    int size;
    char c;
    int steps;

    public group(int size, char c) {
      super();
      this.size = size;
      this.c = c;
    }
  }

  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper in = new InputHelper(inputStream);

    // actual solution
    String sb = in.read();

    StringBuilder s = new StringBuilder(sb);

    int n = s.length();

    List<group> groups = new ArrayList<_909D.group>();

    group cg = null;
    for (int i = 0; i < n; i++) {
      if (i == 0 || s.charAt(i) != s.charAt(i - 1)) {
        if (cg != null) {
          groups.add(cg);
          cg = null;
        }
        cg = new group(1, s.charAt(i));
      } else {
        cg.size++;
      }
    }

    groups.add(cg);

    int ans = 0;
    while (groups.size() > 1) {
      int msz = n;
      for (int i = 0; i < groups.size(); i++) {
        if (i == 0 || i == groups.size() - 1) {
          groups.get(i).steps = groups.get(i).size;
          msz = Math.min(msz, groups.get(i).size);
        } else {
          groups.get(i).steps = (groups.get(i).size + 1) / 2;
          msz = Math.min(msz, (groups.get(i).size + 1) / 2);
        }
      }

      ans += msz;
      for (int i = 0; i < groups.size(); i++) {
        if (i == 0 || i == groups.size() - 1) {
          groups.get(i).size -= msz;
        } else {
          groups.get(i).size -= msz * 2;
          groups.get(i).size = Math.max(groups.get(i).size, 0);
        }
      }

      List<group> ngroups = new ArrayList<_909D.group>();

      for (int i = 0; i < groups.size(); i++) {
        if (ngroups.size() == 0 || ngroups.get(ngroups.size() - 1).c != groups.get(i).c) {
          if (groups.get(i).size > 0) {
            ngroups.add(groups.get(i));
          }
        } else if (ngroups.size() > 0 && ngroups.get(ngroups.size() - 1).c == groups.get(i).c) {
          ngroups.get(ngroups.size() - 1).size += groups.get(i).size;
        }
      }

      groups = ngroups;
    }

    System.out.println(ans);
    // end here
  }

  public static void main(String[] args) throws FileNotFoundException {
    (new _909D()).solve();
  }

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}
