#include <bits/stdc++.h>
using namespace std;
void read(long long &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  x *= f;
  return;
}
long long maxt(long long a, long long b) { return a > b ? a : b; }
long long mint(long long a, long long b) { return a < b ? a : b; }
void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x < 10) {
    putchar('0' + x);
    return;
  }
  write(x / 10);
  putchar(x % 10 + '0');
  return;
}
long long n, maxp, minp, maxn, minn, ans;
char a[1000005];
bool check(long long obs) {
  long long p = 0;
  maxp = minp = 0;
  for (long long i = 1; i < n; i++) {
    if (a[i] == 'R' && obs != p + 1) {
      p++;
      maxp = maxt(p, maxp);
    } else if (a[i] == 'L' && obs != p - 1) {
      p--;
      minp = mint(p, minp);
    }
  }
  if (a[n] == 'R' && obs != p + 1) p++;
  if (a[n] == 'L' && obs != p - 1) p--;
  if (p > maxp) {
    maxp = p;
    return 1;
  }
  if (p < minp) {
    minp = p;
    return 1;
  }
  return 0;
}
int main() {
  char c = getchar();
  while (c != '\n') {
    a[++n] = c;
    c = getchar();
  }
  if (check(0x3f3f3f3f3f3f3f)) {
    printf("1\n");
    return 0;
  }
  minn = minp;
  maxn = maxp;
  long long l = minn, r = 0;
  while (l < r) {
    long long mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  ans += -r;
  l = 0, r = maxn;
  while (l + 1 < r) {
    long long mid = l + r >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  ans += l;
  if (check(l + 1)) ans++;
  printf("%lld", ans);
}
