#include <bits/stdc++.h>
using namespace std;
string s;
void rev() {
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'L')
      s[i] = 'R';
    else
      s[i] = 'L';
}
vector<int> v;
int k[2000011];
const int delta = 1000005;
bool verify(int nr) {
  memset(k, 0, sizeof(k));
  int now = 0;
  k[now + delta]++;
  for (int i = 0; i < v.size(); i++) {
    now = min(nr - 1, now + v[i]);
    k[now + delta]++;
  }
  if (k[now + delta] > 1) return false;
  return true;
}
int i, sum, mx, l, r, mid, ans;
int main(void) {
  cin >> s;
  if (s[s.size() - 1] == 'R') rev();
  for (i = 0; i < s.size(); i++) {
    if (s[i] == 'R')
      v.push_back(1);
    else
      v.push_back(-1);
    sum += v[i];
    mx = max(mx, sum);
  }
  if (verify(mx + 2)) {
    cout << 1;
    return 0;
  }
  l = 1;
  r = mx;
  while (l <= r) {
    mid = (l + r) / 2;
    if (verify(mid) == true) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans;
  return 0;
}
