#include <bits/stdc++.h>
const int N = 1001000;
int f[2 * N], ans;
char s[N];
bool check(int m) {
  int x = 0, l = strlen(s);
  memset(f, 0, sizeof(f));
  f[N] = 1;
  for (int i = 0; i < l; i++) {
    int dx = (s[i] == 'L') ? -1 : 1;
    if (x + dx != m) x += dx;
    f[x + N]++;
  }
  return f[x + N] == 1;
}
int main() {
  scanf("%s", s);
  int l = 0, r = strlen(s);
  if (check(N)) {
    printf("1\n");
    return 0;
  }
  while (l < r) {
    int m = (l + r) / 2 + 1;
    if (check(m))
      l = m;
    else
      r = m - 1;
  }
  ans = l;
  l = -strlen(s), r = 0;
  while (l < r) {
    int m = (l + r) / 2 - 1;
    if (check(m))
      r = m;
    else
      l = m + 1;
  }
  ans -= l;
  printf("%d\n", ans);
  return 0;
}
