x = input()
x = "T" + x + "S"
ar = []
c = 1
for i in range(1, len(x)):
    if x[i-1] == x[i]:
        c += 1
    else:
        ar.append(c)
        c = 1
ar.append(c)
mi = 0
for i in range((len(ar)-2)//2):
    k = i*2 + 1
    mi += min(ar[k], ar[k+1])*2
print(len(x)-2-mi)
