#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;
string s;
int vis[N * 3];
bool judge(int x) {
  int len = s.length();
  int pos = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < len; i++) {
    if (s[i] == 'R' && pos + 1 != x) pos++;
    if (s[i] == 'L' && pos - 1 != x) pos--;
    vis[pos + N]++;
  }
  if (pos != 0 && vis[pos + N] == 1)
    return true;
  else
    return false;
}
int main() {
  cin >> s;
  int len = s.length();
  int pos = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] == 'R') pos++;
    if (s[i] == 'L') pos--;
    vis[pos + N]++;
  }
  if (pos != 0 && vis[pos + N] == 1) {
    cout << 1;
    return 0;
  }
  int ans = 0;
  if (s[len - 1] == 'R') {
    int l = -len, r = -1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (judge(mid)) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    cout << abs(ans);
  } else {
    int l = 1, r = len;
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if (judge(mid)) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    cout << abs(ans);
  }
  return 0;
}
