#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
const int pos = 1000000;
char s[1000005];
bool v[2000005];
bool can(int l, int obs) {
  for (int i = pos - l; i <= pos + l; i++) v[i] = 0;
  int p = 0;
  v[pos] = 1;
  for (int i = 0; i < l - 1; i++) {
    if (s[i] == 'R') {
      if (obs != p + 1) ++p;
      v[p + pos] = 1;
    } else {
      if (obs != p - 1) --p;
      v[p + pos] = 1;
    }
  }
  if (s[l - 1] == 'R')
    ++p;
  else
    --p;
  if (v[p + pos])
    return false;
  else
    return true;
}
int main() {
  scanf("%s", s);
  int l = strlen(s);
  if (can(l, INF))
    puts("1");
  else {
    int tot = 0;
    for (int i = -1; i <= 1; i += 2) {
      if (can(l, i)) {
        int le = 1, ri = 1000000, re = 0;
        while (le <= ri) {
          int m = (le + ri) / 2;
          if (can(l, m * i)) {
            re = m;
            le = m + 1;
          } else
            ri = m - 1;
        }
        tot += re;
      }
    }
    printf("%d\n", tot);
  }
}
