import java.util.*;
public class A{
       public static void main(String args[]){
              Scanner sc = new Scanner(System.in);
              char col[] = sc.next().toCharArray();
              List<int[]> p = new ArrayList<int[]>();
              for(int i = 0; i < col.length; i++){
                     int point[] = new int[]{col[i] - 'a', 1};
                     p.add(point);
              }
              int ans = 0;
              boolean same = true;
              while(true){
                     List<int[]> g = new ArrayList<int[]>();
                     same = true;
                     //do one operation
                     for(int i = 0; i < p.size() - 1; i++){
                            int l[] = p.get(i);
                            int r[] = p.get(i+1);
                            if(l[0] != r[0]){
                                   l[1]--;
                                   r[1]--;
                                   same = false;
                            }
                     }
                     if(same)break;
                     ans++;
                     //ignore empty groups
                     for(int i = 0; i < p.size(); i++){
                            int curr[] = p.get(i);
                            if(curr[1] <= 0)continue;
                            g.add(curr);
                     }
                     p = g;
                     g = new ArrayList<int[]>();
                     int cnt = 0;
                     //merging groups
                      for(int i = 0; i < p.size(); i++){
                            int curr[] = p.get(i);
                          cnt += curr[1];
                          if( i == p.size() - 1 || curr[0] != p.get(i+1)[0]){
                              g.add(new int[]{curr[0], cnt});
                              cnt = 0;
                          }
                      }
                      p = g;
              }
              System.out.println(ans);
       }
}