package work2;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class XingFuNanSheng {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
char[] arr1 = s1.toCharArray();
int count1 = 0;
Map<Integer, Integer> map = new HashMap<>();
//开头元素
if (arr1[0] == 'b') {
for (int l = 1; l < arr1.length - 1; l++) {
if (arr1[l] == 'g') {
count1++;
} else {
break;
}
}
for (int m = arr1.length - 1; m >= 0; m--) {
if (arr1[m] == 'g') {
count1++;
} else {
break;
}
}
map.put(0, count1);
count1 = 0;
}
//结尾元素
if (arr1[arr1.length - 1] == 'b') {
for (int l = 0; l < arr1.length - 1; l++) {
if (arr1[l] == 'g') {
count1++;
} else {
break;
}
}
for (int m = arr1.length - 2; m >= 0; m--) {
if (arr1[m] == 'g') {
count1++;
} else {
break;
}
}
map.put(arr1.length - 1, count1);
count1 = 0;
}
//中间元素
for (int i = 1; i < arr1.length - 1; i++) {
if (arr1[i] == 'b') {
for (int j = i - 1; j >= 0; j--) {
if (arr1[j] == 'g') {
count1++;
} else {
break;
}
}
for (int k = i + 1; k <= arr1.length - 1; k++) {
if (arr1[k] == 'g') {
count1++;
} else {
break;
}
}
map.put(i, count1);
count1 = 0;
}
}
int maxcount2 = 0;
int count2 = 0;
//最长连续的g序列
for(int i=0; i <arr1.length; i++) {
if(arr1[i] == 'g') {
count2++;
}else {
maxcount2 = count2>maxcount2?count2:maxcount2;
count2 = 0;
}
}
System.out.println("count2 "+maxcount2);
int temp = 0;
int max = 0;
for (Integer key : map.keySet()) {
Integer value = map.get(key);
if (max < value) {
max = value;
temp = key;
}
//System.out.println(key + " " + value);
}
System.out.println(temp);
}
}