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