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