colors = input()
n = len(colors)
allR = [0] * (n + 1) # 将i左侧全染成R最少需要的次数
allG = [0] * n # 将i及i右侧全染成G最少需要的次数
for i in range(1, n + 1):
if colors[i-1] == 'G':
allR[i] = allR[i-1] + 1
else:
allR[i] = allR[i-1]
for i in range(n-1, -1, -1):
if i == n - 1:
if colors[i] == 'G':
allG[i] = 0
else:
allG[i] = 1
else:
if colors[i] == 'G':
allG[i] = allG[i+1]
else:
allG[i] = allG[i+1] + 1
allG.append(0)
min_times = n
# 最优解肯定是最在一个分界点使得左边都是R右边都是G
# 遍历分割点
for i in range(n + 1):
times = allR[i] + allG[i]
min_times = min(times, min_times)
print(min_times)