#include <bits/stdc++.h>
char s[1010101];
int arr[2020202];
int* a = arr + 1010101;
int n;
bool ok(int pos) {
  memset(arr, 0, sizeof(arr));
  int t = 0;
  ++a[0];
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'R') {
      if (t + 1 != pos) ++t;
    } else {
      if (t - 1 != pos) --t;
    }
    ++a[t];
  }
  return a[t] == 1;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  if (n == 1) {
    printf("1");
  } else {
    if (ok(1010101)) {
      printf("1");
    } else {
      if (s[n] == 'L') {
        if (ok(1)) {
          int lo = 2;
          int hi = 1000000;
          int pos = 1;
          while (lo <= hi) {
            int mi = (lo + hi) >> 1;
            if (ok(mi)) {
              pos = mi;
              lo = mi + 1;
            } else {
              hi = mi - 1;
            }
          }
          printf("%d", pos);
        } else {
          printf("0");
        }
      } else {
        if (ok(-1)) {
          int lo = 2;
          int hi = 1000000;
          int pos = -1;
          while (lo <= hi) {
            int mi = (lo + hi) >> 1;
            if (ok(-mi)) {
              pos = -mi;
              lo = mi + 1;
            } else {
              hi = mi - 1;
            }
          }
          printf("%d", -pos);
        } else {
          printf("0");
        }
      }
    }
  }
}
