#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
string s;
int n, v[4000000];
bool check(int p) {
  memset(v, 0, sizeof(v));
  int i, c = 0, need = 0;
  for (i = 0; i < n; ++i) {
    v[c + 2000000] = 1;
    if (s[i] == 'L')
      --c;
    else
      ++c;
    if (c == p) ++c, need = 1;
  }
  if (!v[c + 2000000] && need) return true;
  return false;
}
int main() {
  int i, c, l, r, m, ll, ans = 0;
  cin >> s;
  n = (int)s.length();
  if (s[n - 1] == 'L')
    for (i = 0; i < n; ++i)
      if (s[i] == 'L')
        s[i] = 'R';
      else
        s[i] = 'L';
  l = 1e6 + 5;
  c = 0;
  for (i = 0; i < n; ++i) {
    v[c + 2000000] = 1;
    if (s[i] == 'L')
      --c;
    else
      ++c;
    l = min(l, c);
    r = ((r) > (c) ? (r) : (c));
  }
  if (!v[c + 2000000]) cout << 1, exit(0);
  ll = l;
  r = 0;
  while (l < r - 1) {
    m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m + 1;
  }
  for (i = ((ll) > (r - 3) ? (ll) : (r - 3)); i < r; ++i)
    if (check(i)) break;
  if (i < 0)
    cout << -i + ans;
  else
    cout << -r + ans;
}
