#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const int N = 1000009;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long INF64 = 2e18;
const long double PI = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
string s;
bool check(int obstacle, bool xz) {
  int pos = 0, mx = 0;
  bool ok = false;
  for (int i = 0; i < (int)((int)(s.size()) - 1); ++i) {
    pos += (s[i] == 'R' ? 1 : -1);
    if (pos == obstacle) ok = true, ++pos;
    mx = max(pos, mx);
  }
  return pos == mx && (ok || xz);
}
int main() {
  srand(time(NULL));
  cout << setprecision(10) << fixed;
  cerr << setprecision(10) << fixed;
  cin >> s;
  if (s[(int)(s.size()) - 1] == 'L')
    for (int i = 0; i < (int)((int)(s.size())); ++i)
      s[i] = (s[i] == 'L' ? 'R' : 'L');
  int ans = check(-INF, true);
  if (ans) {
    cout << 1;
    return 0;
  }
  int l = -INF, r = -1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (check(m, false))
      r = m;
    else
      l = m;
  }
  int cur = 0;
  assert(r > l);
  for (int i = l; i <= r; ++i)
    if (check(i, false)) cur = i;
  cout << ans - cur;
  return 0;
}
