#include <bits/stdc++.h>
using namespace std;
int N;
char A[1000002];
bool Test(int x) {
  int wh = 0, whmax = 0, pmax = 1;
  for (int i = 1; i <= N; ++i) {
    wh += (A[i] == 'R' ? 1 : -1);
    if (wh == x) ++wh;
    if (wh > whmax) {
      whmax = wh;
      pmax = 1;
    } else if (wh == whmax)
      ++pmax;
  }
  if (wh == whmax && pmax == 1) return true;
  return false;
}
int main() {
  cin >> (A + 1);
  N = strlen(A + 1);
  if (A[N] == 'L') {
    for (int i = 1; i <= N; ++i)
      if (A[i] == 'R')
        A[i] = 'L';
      else
        A[i] = 'R';
  }
  if (Test(-N)) {
    cout << 1 << '\n';
    return 0;
  }
  if (!Test(-1)) {
    cout << 0 << '\n';
    return 0;
  }
  int step = (1 << 19), result = 0;
  for (; step; step >>= 1)
    if (result + step <= N && Test(-(result + step))) result += step;
  cout << result << '\n';
}
