#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
char s[1100000];
int at[3000000];
int main() {
  int i, x, n, l, r, mid;
  scanf("%s", s);
  n = strlen(s);
  if (s[n - 1] == 'R')
    for (i = 0; i < n; i++) s[i] ^= 'L' ^ 'R';
  for (i = 0, x = 1100000, at[x] = 1; i < n; i++) {
    x += s[i] == 'L' ? -1 : 1;
    at[x]++;
  }
  if (at[x] == 1) {
    puts("1");
    return 0;
  }
  l = 1;
  r = n;
  while (l <= r) {
    mid = (l + r) / 2;
    memset(at, 0, sizeof(at));
    for (i = 0, x = 1100000, at[x] = 1; i < n; i++) {
      x += s[i] == 'L' ? -1 : 1;
      x -= x == 1100000 + mid;
      at[x]++;
    }
    if (at[x] == 1)
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", l - 1);
}
