#include <bits/stdc++.h>
using namespace std;
int M[1000005], N;
string S;
bool ok(int o) {
  int l = 0, r = 0, p = 0;
  for (int i = 0; i < N - 1; i++) {
    if (p + M[i] == o) continue;
    p += M[i];
    l = min(l, p);
    r = max(r, p);
  }
  return p == r;
}
int main() {
  cin >> S;
  N = S.length();
  for (int i = 0; i < N; i++) M[i] = S[i] == 'L' ? -1 : 1;
  if (M[N - 1] < 0)
    for (int i = 0; i < N; i++) M[i] *= -1;
  if (ok(-N - 2)) {
    cout << 1;
    return 0;
  }
  int a = -N, b = -1;
  int p = (a + b) / 2;
  while (b - a > 1) {
    if (ok(p))
      b = p;
    else
      a = p;
    p = (a + b) / 2;
  }
  if (ok(b))
    cout << -b;
  else if (ok(a))
    cout << -a;
  else
    cout << 0;
}
