/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String setofletters = "aaakkcccccczz"; /* 15 */
        int output = runLongestIndex(setofletters);
        System.out.println("Longest run that first appeared in index : " + output);
    }

    public static int runLongestIndex(String setofletters) {
      int maxCount = 0;
      int maxIndex = 0;
    
      // loops each character in the string
      for (int i = 0; i < setofletters.length() - 1; ) {
        // new char sequence starts here
        char currChar = setofletters.charAt(i);
        int count = 1;
        int index = i;
        while ( (index < setofletters.length() - 1) &&
                (currChar == setofletters.charAt(++index)) ) {
           count++;
        } 
          
        if (count > maxCount) {
           maxIndex = i;
           maxCount = count;
        }
        i = index;
      }
      return maxIndex;
    }
}