#include <bits/stdc++.h>
using namespace std;
string s;
bool ch[2010000];
bool check(int l) {
  int now = 0;
  fill(ch, ch + 2001000, 0);
  ch[1000000] = 1;
  for (int i = 0; i < s.length() - 1; i++) {
    if (s[i] == 'L')
      now++;
    else
      now--;
    if (now == l) now--;
    ch[now + 1000000] = 1;
  }
  if (!ch[now - 1 + 1000000]) return 1;
  return 0;
}
int BS(int l, int r) {
  if ((l + r) / 2 == l) {
    if (check(r))
      return r;
    else
      return l;
  }
  int m = (l + r) / 2;
  if (check(m)) return BS(m, r);
  return BS(l, m);
}
void reverss() {
  for (int i = 0; i < s.length(); i++)
    if (s[i] == 'R')
      s[i] = 'L';
    else
      s[i] = 'R';
}
int main() {
  cin >> s;
  if (s[s.length() - 1] == 'L') reverss();
  if (check(1111111)) {
    cout << 1 << endl;
    return 0;
  }
  if (!check(1)) {
    cout << 0 << endl;
    return 0;
  }
  check(1);
  int ans = BS(1, 1000000);
  cout << ans << endl;
  return 0;
}
