import java.util.Scanner;

public class Main6 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
char[] cs = in.nextLine().toCharArray();
int n = cs.length;
System.out.println(minPaint(cs, 0, n-1));
}
}
static int minPaint(char[] cs ,Integer start,int end){
int left = 0;
int right = 0;
int minLeft = 0;
int minRight = 0;
while(cs[start]=='R'&&start<end){
start++;
}
while(cs[end]=='G'&&end>start){
end--;
}
if(start>=end){
return 0;
}
while(cs[start+left]=='G'){
left++;
}
minLeft = left+minPaint(cs, start+left,end);
while(cs[end-right]=='R'){
right++;
}
minRight = right+minPaint(cs, start, end-right);
return Math.min(minLeft, minRight);
}
}