#include <bits/stdc++.h>
using namespace std;
string a;
int l = 0, r = 1000005, mid;
bool check(int cnt) {
  cnt--;
  int minn = 0;
  int now = 0, _ind = 1;
  for (int i = 0; i < a.length(); i++) {
    if (a[i] == 'L')
      now--;
    else {
      now = min(cnt, now + 1);
    }
    if (now == minn) _ind++;
    if (now < minn) {
      _ind = 1;
      minn = now;
    }
  }
  if (now == minn && _ind == 1) return 1;
  return 0;
}
int main() {
  cin >> a;
  if (a[a.length() - 1] == 'R') {
    for (int i = 0; i < a.length(); i++)
      if (a[i] == 'L')
        a[i] = 'R';
      else
        a[i] = 'L';
  }
  if (check(INT_MAX)) {
    cout << "1";
    return 0;
  }
  while (l + 1 < r) {
    mid = (l + r) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  while (check(l + 1) == 1) l++;
  cout << l;
  return 0;
}
