#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long l = 0, r = 0, u = 0, d = 0, a, b, L;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == 'L') l++;
    if (s[i] == 'R') r++;
    if (s[i] == 'U') u++;
    if (s[i] == 'D') d++;
  }
  L = s.size();
  if (L % 2 == 0) {
    a = abs(l - r);
    b = abs(u - d);
    if (a >= b) {
      long long d = b;
      a -= b;
      d += (a / 2);
      cout << d << endl;
    } else {
      long long d = a;
      b -= a;
      d += (b / 2);
      cout << d << endl;
    }
  } else
    cout << "-1" << endl;
}
