#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const double EPS = 1e-8;
int cmp(double x, double y = 0, double tol = EPS) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
string s;
bool test(long long inx) {
  int pos = 0;
  int m = 0;
  int im = 0;
  for (auto &x : s) {
    if (x == 'R')
      pos++;
    else
      pos--;
    if (inx >= 0 && pos == inx) pos--;
    if (pos < m) {
      m = pos;
      im = &x - &(s[0]);
    }
  }
  return im == s.size() - 1;
}
int main() {
  cin >> s;
  if (s.back() == 'R')
    for (auto &x : s) x = 'R' + 'L' - x;
  if (test(-1)) {
    cout << "1\n";
    return 0;
  } else if (!test(1)) {
    cout << "0\n";
    return 0;
  }
  long long m = 1, M = 0x7fffffffffffffffll;
  long long ans = 1;
  while (M >= m) {
    long long med = m + (M - m) / 2;
    if (test(med)) {
      ans = med;
      m = med + 1;
    } else
      M = med - 1;
  }
  cout << ans << endl;
  return 0;
}
