#include <bits/stdc++.h>
using namespace std;
string s;
long long N;
void change() {
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'L') {
      s[i] = 'R';
    } else {
      s[i] = 'L';
    }
  }
}
bool good(int p) {
  int curr = 0, step = 0, ma = 0, cnt = 1;
  bool v = 0;
  for (int i = 0; i < N; ++i) {
    if (s[i] == 'R') {
      step = 1;
    } else {
      step = -1;
    }
    if (curr + step != p) {
      curr += step;
    } else {
      v = 1;
    }
    if (ma < curr) {
      ma = curr;
      cnt = 1;
    } else if (ma == curr) {
      ++cnt;
    }
  }
  if (ma == curr && cnt == 1 && v) {
    return true;
  }
  return false;
}
long long caut() {
  long long st = -N, dr = -1, ret = 0;
  while (st <= dr) {
    long long p = (st + dr) / 2;
    if (good(p)) {
      ret = p;
      dr = p - 1;
    } else {
      st = p + 1;
    }
  }
  return ret;
}
bool noObs() {
  int curr = 0, step = 0, ma = 0, cnt = 1;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'R') {
      step = 1;
    } else {
      step = -1;
    }
    curr += step;
    if (ma < curr) {
      ma = curr;
      cnt = 1;
    } else if (ma == curr) {
      ++cnt;
    }
  }
  if (ma == curr && cnt == 1) {
    return true;
  }
  return false;
}
int main() {
  cin >> s;
  N = s.size();
  if (s[N - 1] == 'L') {
    change();
  }
  if (noObs()) {
    cout << 1;
  } else {
    cout << -caut();
  }
  return 0;
}
