#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int i = 0; i < t.size(); i++) s << t[i] << " ";
  return s;
}
char s[1000010];
int n, f[1000010 * 6], st = 0;
bool can(int z) {
  st++;
  int first = 2e6;
  z += 2e6;
  f[first] = st;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L' && z != first - 1) first--;
    if (s[i] == 'R' && z != first + 1) first++;
    if (i == n - 1) {
      if (f[first] == st) return 0;
      return 1;
    }
    f[first] = st;
  }
}
int main() {
  int m, i, j, k, T;
  while (~scanf("%s", s)) {
    n = strlen(s);
    if (can((int)1e9)) {
      puts("1");
      continue;
    } else {
      int ans = 0;
      for (i = -1; i < 2; i += 2)
        if (can(i)) {
          int l = 1, r = 1e6 + 10;
          while (l <= r) {
            m = (l + r) >> 1;
            if (can(m * i))
              l = m + 1;
            else
              r = m - 1;
          }
          ans += l - 1;
        }
      printf("%d\n", ans);
    }
  }
  return 0;
}
