#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  string s;
  cin>>s;
  int ans=0;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='L')cnt--;
    else cnt++;
    if(cnt==-4)cnt=0;
    if(cnt==4)cnt=0,ans++;
  }
  cout<<ans<<endl;
  return 0;
}

