///Chefer

#include<bits/stdc++.h>
#define int long long int 
#define f first
#define s second

using namespace std;

typedef pair<int,int> pii;
string s;
struct ll
{
	ll* pre;
	ll* nxt;
	int x;
	char tp;
	ll(int x_=0,char tp_='&',ll* nxt_=NULL,ll* pre_=NULL)
	{
		tp=tp_;
		x=x_;
		nxt=nxt_;
		pre=pre_;
	}
};
main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin>>s;
	ll* start=new ll();
	ll* finish=new ll();
	start->nxt=finish;
	finish->pre=start;
	start->tp='S';
	finish->tp='F';
	s+="#";
	ll* p=start;
	int t=0;
	for(int i=0;i<s.size()-1;i++)
	{
		t++;
		if(s[i]!=s[i+1])
		{
			ll* neww=new ll();
			neww->x=t;
			neww->tp=s[i];
			neww->nxt=p->nxt;
			neww->pre=p;
			p->nxt=neww;
			neww->nxt->pre=neww;
			t=0;
		}
	}
	int ans=0;
	ll* tmp;
	while(start->nxt!=finish&&start->nxt->nxt!=finish)
	{
		ans++;
		/*
		p=start->nxt;
		while(p!=finish)
		{
			cout<<p->tp<<" "<<p->x;
			cout<<endl;
			p=p->nxt;
		}
		cerr<<endl;
		*/
		p=start->nxt;
		while(p!=finish)
		{
			if(p->nxt==finish||p->pre==start)
				p->x--;
			else
				p->x-=2;
			p=p->nxt;
		}
		/*
		p=start->nxt;
		while(p!=finish)
		{
			cout<<p->tp<<" "<<p->x;
			cout<<endl;
			p=p->nxt;
		}
		cerr<<endl<<"SHIT"<<endl;
		*/
		p=start->nxt;
		while(p!=finish)
		{
			tmp=p;
			p=p->nxt;
			if(tmp->x<1)
			{
				p->pre=tmp->pre;
				tmp->pre->nxt=p;
				if(p->tp==p->pre->tp)
				{
					tmp=p->pre;
					p->x+=tmp->x;
					p->pre=tmp->pre;
					tmp->pre->nxt=p;
				}
			}
		}
	}
	cout<<ans;
	return 0;
}
