#include <bits/stdc++.h>
using namespace std;
string a;
char l, r;
int n;
bool judge(int x) {
  int now = 0, l = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 'L') {
      now--;
      if (i == n - 1) {
        if (now < l) return true;
        return false;
      }
      if (now < l) l = now;
    } else {
      if (now + 1 < x) now++;
    }
  }
}
int main() {
  cin >> a;
  n = a.size();
  if (a[n - 1] == 'R') {
    for (int i = 0; i < n; i++) {
      if (a[i] == 'R')
        a[i] = 'L';
      else
        a[i] = 'R';
    }
  }
  if (judge(n)) {
    cout << "1" << endl;
    return 0;
  }
  int l = 1, r = n - 1, ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (judge(mid))
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  if (ans != -1)
    cout << ans << endl;
  else
    cout << "0" << endl;
  return 0;
}
