#include <bits/stdc++.h>
using namespace std;
const int N = 2000010;
const int eps = 1000000;
int visit[N];
char s[N];
void run(int pos, int &maxx, int &maxy, int &last) {
  memset(visit, 0, sizeof(visit));
  visit[eps] = 1;
  int now = eps;
  maxx = maxy = now;
  for (int i = 0; s[i]; i++) {
    if (s[i] == 'L')
      now--;
    else
      now++;
    if (now == pos) {
      if (s[i] == 'L')
        now++;
      else
        now--;
    }
    maxx = min(maxx, now);
    maxy = max(maxy, now);
    visit[now]++;
  }
  last = now;
}
int main() {
  scanf("%s", s);
  int maxx, maxy, last, x, y;
  run(0x7fffffff, maxx, maxy, last);
  if (visit[last] == 1) {
    cout << 1 << endl;
    return 0;
  }
  int lt = eps + 1, rt = maxy, mid, ans = -1;
  while (lt <= rt) {
    mid = (lt + rt) >> 1;
    run(mid, x, y, last);
    if (visit[last] == 1)
      ans = mid, lt = mid + 1;
    else
      rt = mid - 1;
  }
  if (ans != -1) {
    cout << ans - eps << endl;
    return 0;
  }
  lt = maxx, rt = eps - 1, mid;
  while (lt <= rt) {
    mid = (lt + rt) >> 1;
    run(mid, x, y, last);
    if (visit[last] == 1)
      ans = mid, rt = mid - 1;
    else
      lt = mid + 1;
  }
  if (ans != -1)
    cout << eps - ans << endl;
  else
    cout << 0 << endl;
  return 0;
}
