#include <bits/stdc++.h>
using namespace std;
char s[1100000];
int len, vst[1100000 << 1], rid;
bool possible(int x) {
  int cur = 0, i;
  rid++;
  for (i = 0; i < len; i++) {
    vst[cur + 1100000] = rid;
    if (s[i] == 'L')
      cur--;
    else
      cur++;
    if (cur == -x) cur++;
  }
  return cur > 0 && vst[cur + 1100000] < rid;
}
int main() {
  int i, j, L, R, high, low, mid, cur;
  scanf("%s", s);
  len = strlen(s);
  for (i = 1; i < len; i++)
    if (s[i] != s[i - 1]) break;
  if (i == len) {
    puts("1");
    return 0;
  }
  if (s[len - 1] == 'L') {
    for (i = 0; i < len; i++)
      if (s[i] == 'L')
        s[i] = 'R';
      else
        s[i] = 'L';
  }
  cur = 0;
  rid++;
  for (i = 0; i < len; i++) {
    vst[cur + 1100000] = rid;
    if (s[i] == 'L')
      cur--;
    else
      cur++;
  }
  if (vst[1100000 + cur] < rid) {
    puts("1");
    return 0;
  }
  high = len;
  low = 0;
  while (high > low + 1) {
    mid = (high + low) / 2;
    if (possible(mid))
      low = mid;
    else
      high = mid;
  }
  if (possible(high))
    printf("%d\n", high);
  else
    printf("%d\n", low);
  return 0;
}
