#include <bits/stdc++.h>
using namespace std;
char str[int(1e6) + 10];
int strsize;
int a[int(1e6) + 10];
int asize = 0;
int check(int mx) {
  int cur = 0;
  int mn = 0;
  int mncnt = 1;
  for (int i = 0; i < asize; ++i) {
    cur = min(mx - 1, cur + a[i]);
    if (cur == mn) ++mncnt;
    if (cur < mn) mn = cur, mncnt = 1;
  }
  return cur == mn && mncnt == 1;
}
void solve() {
  scanf("%s", str);
  strsize = strlen(str);
  int left = 0;
  for (int i = 1; i < strsize; ++i) {
    if (str[i] != str[left]) {
      if ((str[left] == 'R') == (str[strsize - 1] == 'L'))
        a[asize++] = i - left;
      else
        a[asize++] = -(i - left);
      left = i;
    }
  }
  if ((str[left] == 'R') == (str[strsize - 1] == 'L'))
    a[asize++] = strsize - left;
  else
    a[asize++] = -(strsize - left);
  int mx = 0, mn = 0;
  int mncnt = 1, mxcnt = 1;
  int cur = 0;
  for (int i = 0; i < asize; ++i) {
    cur += a[i];
    if (mx == cur) ++mxcnt;
    if (mn == cur) ++mncnt;
    if (cur > mx) {
      mx = cur;
      mxcnt = 1;
    }
    if (cur < mn) {
      mn = cur;
      mncnt = 1;
    }
  }
  int ok = 0;
  if (mncnt == 1 && cur == mn && a[asize - 1] < 0) ok = 1;
  if (mxcnt == 1 && cur == mx && a[asize - 1] > 0) ok = 1;
  if (ok) {
    printf("1\n");
    return;
  }
  left = 0;
  int right = int(1e6) + 100;
  while (left + 1 < right) {
    int middle = (left + right) / 2;
    if (check(middle))
      left = middle;
    else
      right = middle;
  }
  printf("%d\n", left);
}
int main() {
  solve();
  return 0;
}
