#include <bits/stdc++.h>
using namespace std;
long long int i, j, n;
int main() {
  long long int ans = 0;
  long long int cr = 0, cu = 0, cl = 0, cd = 0;
  string s;
  cin >> s;
  n = s.size();
  for (i = 0; i < n; i++) {
    if (s[i] == 'R')
      cr++;
    else if (s[i] == 'U')
      cu++;
    else if (s[i] == 'L')
      cl++;
    else if (s[i] == 'D')
      cd++;
  }
  long long int x = abs(cr - cl);
  long long int y = abs(cu - cd);
  if ((abs(x - y)) % 2 == 0) {
    ans = min(x, y) + abs(x - y) / 2;
    cout << ans;
  } else
    cout << "-1";
  return 0;
}
