#include <bits/stdc++.h>
using namespace std;
int v[2222222], len;
char order[2222222];
bool check(int now) {
  memset(v, 0, sizeof(v));
  int tmp = 1111111;
  v[tmp]++;
  for (int i = 0; i < len; i++) {
    if (order[i] == 'R')
      tmp++;
    else
      tmp--;
    if (now == tmp - 1111111) tmp--;
    v[tmp]++;
  }
  return v[tmp] == 1;
}
int main() {
  int i;
  scanf("%s", order);
  len = strlen(order);
  if (order[len - 1] == 'R') {
    for (i = 0; i < len; i++)
      if (order[i] == 'L')
        order[i] = 'R';
      else
        order[i] = 'L';
  }
  if (check(2222222)) {
    printf("1\n");
    exit(0);
  }
  int l = 0, r = 1111111, mid;
  while (r > l + 1) {
    mid = (l + r) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  if (check(r) == 0) r = r - 1;
  if (r > 0)
    printf("%d\n", r);
  else
    printf("0\n");
}
