#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  while (cin >> s) {
    int len = s.size();
    if (len % 2 == 1) {
      printf("-1\n");
      continue;
    }
    map<char, int> m;
    for (int i = 0; i < len; ++i) m[s[i]]++;
    int ud = abs(m['U'] - m['D']);
    int lf = abs(m['L'] - m['R']);
    if (ud == lf) {
      printf("%d\n", ud);
      continue;
    }
    if (ud == 0 && lf != 0) {
      printf("%d\n", lf / 2);
      continue;
    }
    if (lf == 0 && ud != 0) {
      printf("%d\n", ud / 2);
      continue;
    }
    if (lf != 0 && ud != 0) {
      int minn = min(lf, ud);
      int n = minn + abs(lf - ud) / 2;
      printf("%d\n", n);
      continue;
    }
    if (ud != lf) {
      printf("-1\n");
      continue;
    }
  }
}
