#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int SHIFT = 1e6 + 2;
const int inf = 2e9;
int saw[maxn + maxn + 100];
int viz[maxn];
bool ok(const string& s, int banned) {
  int ptr = -1;
  int at = 0;
  for (char c : s) {
    int to = c == 'R' ? at + 1 : at - 1;
    if (to == banned) continue;
    at = to;
    viz[++ptr] = to;
    saw[to + SHIFT]++;
  }
  bool ret = (at != 0 && saw[at + SHIFT] == 1);
  while (ptr >= 0) {
    saw[viz[ptr] + SHIFT]--;
    --ptr;
  }
  return ret;
}
string s;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  n = s.length();
  if (ok(s, inf)) out(1);
  if (ok(s, 1)) {
    int lo = 1;
    int hi = maxn;
    while (hi - lo > 1) {
      int mid = (lo + hi) / 2;
      if (ok(s, {mid})) {
        lo = mid;
      } else {
        hi = mid;
      }
    }
    out(lo);
  }
  if (ok(s, -1)) {
    int lo = 1;
    int hi = maxn;
    while (hi - lo > 1) {
      int mid = (lo + hi) / 2;
      if (ok(s, -mid)) {
        lo = mid;
      } else {
        hi = mid;
      }
    }
    out(lo);
  }
  out(0);
  return 0;
}
