#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int n, ar[2 * 1000005], fr[2 * 1000005];
long long check(long long);
int main() {
  scanf(" %s", str + 1);
  n = strlen(str + 1);
  if (str[n] == 'L')
    for (int i = 1; i < n + 1; i++) str[i] = (str[i] == 'L' ? 'R' : 'L');
  int min_ = 0;
  fr[1000005]++;
  for (int i = 1; i < n + 1; i++) {
    ar[i] = (ar[i - 1] + (str[i] == 'R' ? 1 : -1));
    fr[ar[i] + 1000005]++;
    min_ = min(min_, ar[i]);
  }
  if (fr[ar[n] + 1000005] == 1) {
    printf("1\n");
    return 0;
  }
  long long low = min_, high = -1, ans = 0, mid = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check(mid)) {
      ans = abs(mid);
      high = mid - 1;
    } else
      low = mid + 1;
  }
  printf("%lld", ans);
}
long long check(long long val) {
  memset(fr, 0, sizeof(fr));
  fr[1000005] = 1;
  long long tot = 0;
  for (int i = 1; i < n + 1; i++) {
    if (str[i] == 'R')
      tot++;
    else
      tot--;
    if (tot == val) tot = val + 1;
    fr[tot + 1000005]++;
  }
  return fr[tot + 1000005] == 1;
}
