#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int l = 0, d = 0, u = 0, r = 0, diff1 = 0, diff2 = 0;
  cin >> s;
  if ((s.length() % 2) != 0)
    cout << -1 << endl;
  else {
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'L') l++;
      if (s[i] == 'D') d++;
      if (s[i] == 'U') u++;
      if (s[i] == 'R') r++;
    }
    if ((l + r) % 2 == 0 && (d + u) % 2 == 0)
      cout << abs((l - r) / 2) + abs(d - u) / 2 << endl;
    else {
      diff1 = max(l, r) - min(l, r);
      diff2 = max(u, d) - min(u, d);
      if (abs(diff1 - diff2) % 2 == 0)
        cout << min(diff1, diff2) + abs(diff1 - diff2) / 2;
      else
        cout << -1;
    }
  }
  return 0;
}
