#include <bits/stdc++.h>
using namespace std;
string s;
int n, ans, tong, mmin, p;
int f[1111111][2], g[1111111];
bool ok[1111111];
int main() {
  getline(cin, s);
  n = int(s.size()) - 1;
  if (s[n] != 'R') {
    for (int i = 0; i <= n; i++)
      if (s[i] == 'L')
        s[i] = 'R';
      else
        s[i] = 'L';
  }
  int tong = 0, mmin = 0, ans = -1000000000, sum = 0, value;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'R')
      tong++;
    else
      tong--;
    value = tong - mmin;
    mmin = min(mmin, tong);
    if (value > ans)
      ans = value, sum = 1;
    else if (value == ans)
      sum++;
    f[i][0] = ans;
    f[i][1] = sum;
  }
  f[n][0] = -1000000000;
  f[n][1] = 0;
  tong = 0;
  for (int i = 0; i <= n; i++) {
    if (s[i] == 'R')
      tong++;
    else
      tong--;
    g[i] = tong;
  }
  ans = 0;
  for (int i = 0; i <= n; i++) {
    if (s[i] == 'R')
      tong++;
    else
      tong--;
    if (tong > ans)
      ans = tong, sum = 1;
    else if (tong == ans)
      sum++;
  }
  if (tong == ans)
    if (sum == 1) {
      cout << 1;
      return 0;
    }
  for (int i = n - 1; i >= 0; i--) g[i] = min(g[i], g[i + 1]);
  int full = 0;
  if (g[n] - min(0, g[0]) > f[0][0]) full++;
  tong = 0;
  ans = 0;
  sum = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'R')
      tong++;
    else
      tong--;
    ans = max(ans, tong);
    if (tong < sum) {
      sum = tong;
      if (g[n] - g[i - 1] + sum > ans)
        if (g[n] - g[i - 1] > f[i][0]) full++;
    }
  }
  cout << full;
  return 0;
}
