#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
char s[N];
int f[N * 2], len;
bool pd(int x) {
  x += 1000000;
  memset(f, 0, sizeof(f));
  int sum = 1000000;
  f[sum] = 1;
  for (int i = 0; i < len; i++) {
    sum += (s[i] == 'L' ? -1 : 1);
    if (sum == x) sum = x - 1;
    f[sum]++;
  }
  if (f[sum] == 1)
    return true;
  else
    return false;
}
int main() {
  scanf("%s", s);
  len = strlen(s);
  int sum = 1000000, max = 0, min = 0;
  f[sum] = 1;
  for (int i = 0; i < len; i++) {
    sum += (s[i] == 'L' ? -1 : 1);
    f[sum]++;
    max = ((max) > (sum) ? (max) : (sum));
    min = ((min) < (sum) ? (min) : (sum));
  }
  if (f[sum] == 1) {
    printf("1\n");
    return 0;
  }
  if (s[len - 1] == 'R') {
    for (int i = 0; i < len; i++)
      if (s[i] == 'L')
        s[i] = 'R';
      else
        s[i] = 'L';
  }
  int l = 1, r = 1000000;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (pd(mid))
      l = mid;
    else
      r = mid - 1;
  }
  if (pd(r))
    printf("%d\n", r);
  else
    printf("0\n");
  return 0;
}
