#include <bits/stdc++.h>
using namespace std;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {1, -1, 0, 0};
int n;
char s[int(1e6 + 100)];
bool check(int l, int r) {
  int _min = 0;
  int _max = 0;
  int cnt_min = 1;
  int cnt_max = 1;
  int x = 0;
  for (int i = (1), _b = (n); i <= _b; i++) {
    if (s[i] == 'R') {
      if (x + 1 > l && x + 1 < r) x += 1;
    } else {
      if (x - 1 > l && x - 1 < r) x -= 1;
    }
    if (x < _min) {
      _min = x;
      cnt_min = 1;
    } else if (x == _min) {
      cnt_min++;
    }
    if (x > _max) {
      _max = x;
      cnt_max = 1;
    } else if (x == _max) {
      cnt_max++;
    }
  }
  if (x == _min && cnt_min == 1) {
    return true;
  }
  if (x == _max && cnt_max == 1) {
    return true;
  }
  return false;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  if (check(-int(1e9), int(1e9))) {
    cout << 1 << endl;
    return 0;
  }
  int l = -int(1e9), r = -1, res = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid, int(1e9))) {
      res = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  int sum = 0;
  sum += -res;
  l = 1;
  r = int(1e9);
  res = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(-int(1e9), mid)) {
      res = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  sum += res;
  cout << sum << endl;
}
