#include <bits/stdc++.h>
using namespace std;
bool maximize(int &a, int b) {
  if (a < b)
    a = b;
  else
    return false;
  return true;
}
void answer(int x) {
  cout << x << endl;
  exit(0);
}
int n;
char a[1000006];
bool ok(int Blocked) {
  int Pos = 0, Max = 0, Cnt = 1;
  for (int i = 1; i <= n; i++) {
    if (Pos + a[i] != Blocked) Pos += a[i];
    if (maximize(Max, Pos)) Cnt = 0;
    if (Pos == Max) Cnt++;
  }
  return Pos == Max && Cnt == 1;
}
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  if (a[n] == 'L')
    for (int i = 1; i <= n; i++) a[i] ^= 30;
  for (int i = 1; i <= n; i++) a[i] = (a[i] == 'L' ? -1 : 1);
  if (ok(0x3c3c3c3c)) answer(1);
  if (!ok(-1)) answer(0);
  int ll = 1, rr = 0x3c3c3c3c, mm = (ll + rr) / 2;
  while (ll < mm && mm < rr) {
    if (ok(-mm))
      ll = mm;
    else
      rr = mm;
    mm = (ll + rr) / 2;
  }
  for (int i = ll; i <= rr; i++)
    if (!ok(-i)) answer(i - 1);
}
