#include <bits/stdc++.h>
using namespace std;
string s;
bool valid(int k) {
  int pos = 0;
  vector<int> used(3 * 1e6, 0);
  used[pos + 1e6] = 1;
  for (char c : s) {
    if (c == 'L')
      pos--;
    else
      pos++;
    pos = min(pos, k - 1);
    used[pos + 1e6]++;
  }
  return used[pos + 1e6] == 1;
}
int main() {
  cout.sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  int n = s.size();
  if (valid(1e9)) {
    cout << 1 << endl;
    return 0;
  }
  if (s[n - 1] == 'R') {
    for (int i = 0; i < n; i++) s[i] = (s[i] == 'L' ? 'R' : 'L');
  }
  int res = 0, esq = 1, dir = 1e9;
  while (esq <= dir) {
    int mid = (esq + dir) / 2;
    if (valid(mid))
      res = max(res, mid), esq = mid + 1;
    else
      dir = mid - 1;
  }
  cout << res << endl;
  return 0;
}
