#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
const char dir[] = "LR";
const int step[] = {-1, 1};
char str[MAXN + 5];
int n;
void reverseDirection() {
  for (int c = 0; str[c]; c++) {
    if (str[c] == 'L')
      str[c] = 'R';
    else
      str[c] = 'L';
  }
}
bool check(int limit) {
  int pos = 0;
  int maxi = 0;
  for (int c = 0; c + 1 < n; c++) {
    pos += step[strchr(dir, str[c]) - dir];
    if (pos < limit) pos = limit;
    maxi = max(maxi, pos);
  }
  return maxi == pos;
}
int main() {
  int c, c2;
  scanf("%s", str);
  n = strlen(str);
  if (str[n - 1] == 'L') reverseDirection();
  int pos = 0, mini = 0;
  for (c = 0; c < n; c++) {
    pos += step[strchr(dir, str[c]) - dir];
    mini = min(mini, pos);
  }
  int s = 0, e = -mini;
  int ret = -1;
  while (s <= e) {
    int mid = s + e >> 1;
    if (check(-mid)) {
      s = mid + 1;
      ret = mid;
    } else
      e = mid - 1;
  }
  if (check(mini)) ret = 0;
  printf("%d\n", ret + 1);
}
