#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int nmax = 100010;
long long res;
long double eps = 1e-6;
int n, m, k, a, b, c, d, x, y, l, r, z;
string s;
int main() {
  cin >> s;
  n = s.length();
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'U') ++a;
    if (s[i] == 'D') ++b;
    if (s[i] == 'R') ++c;
    if (s[i] == 'L') ++d;
  }
  m = abs(a - b) + abs(c - d);
  if (m % 2) {
    cout << -1;
  } else {
    cout << m / 2 << endl;
  }
  return 0;
}
