#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int MAX = 1000100;
int n;
char D[MAX];
bool check(int k) {
  int mini = 0, imini = -1, sum = 0;
  for (int i = 0; i < n; i++) {
    if (sum + D[i] == k) continue;
    sum += D[i];
    if (sum < mini) {
      mini = sum;
      imini = i;
    }
  }
  return (imini == n - 1);
}
int BS(int a, int b) {
  if (b < a) return 0;
  if (a == b) return (a * check(a));
  int sr = (a + b + 1) / 2;
  if (check(sr))
    return BS(sr, b);
  else
    return BS(a, sr - 1);
}
int solve() {
  scanf("%s", D);
  n = strlen(D);
  for (int i = 0; i < n; i++) D[i] = D[i] == 'L' ? -1 : 1;
  int mini = 0, imini = -1, maxi = 0, imaxi = -1, sum = 0;
  for (int i = 0; i < n; i++) {
    sum += D[i];
    if (sum < mini) {
      mini = sum;
      imini = i;
    }
    if (sum > maxi) {
      maxi = sum;
      imaxi = i;
    }
  }
  if (imini == n - 1 || imaxi == n - 1) return 1;
  int ans1 = 0;
  ans1 = BS(1, maxi);
  for (int i = 0; i < n; i++) D[i] *= -1;
  int ans2 = 0;
  ans2 = BS(1, (-1) * mini);
  return ans1 + ans2;
}
int main() {
  int tests = 1;
  for (int i = 1; i <= tests; i++) {
    printf("%d\n", solve());
  }
}
