#include <bits/stdc++.h>
int Max(const int x, const int y) {
  if (x > y) return x;
  return y;
}
int Min(const int x, const int y) {
  if (x < y) return x;
  return y;
}
const int M = 1e6 + 5;
int n, vis[M << 1];
char s[M];
bool check(const int x) {
  int now = M;
  memset(vis, 0, sizeof vis);
  vis[now] = 1;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'L' && now - 1 != x) --now;
    if (s[i] == 'R' && now + 1 != x) ++now;
    ++vis[now];
  }
  return vis[now] < 2;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  int x = M, left = M, right = M;
  vis[M] = 1;
  for (int i = 0; i < n; ++i) {
    if (s[i] ^ 'R')
      --x;
    else
      ++x;
    ++vis[x];
    left = Min(left, x);
    right = Max(right, x);
  }
  if (vis[x] < 2) return !putchar('1');
  int l = left, r = M - 1, mid, p = M;
  while (l <= r) {
    mid = l + r >> 1;
    if (check(mid))
      p = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  int ans = M - p;
  l = M + 1, r = right, p = M;
  while (l <= r) {
    mid = l + r >> 1;
    if (check(mid))
      p = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  ans += p - M;
  printf("%d", ans);
  return 0;
}
