#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[100004];
  long long int i, j, k, l, a[100070], b[100078], n, p, p2, min;
  cin >> s;
  a[1] = a[2] = a[3] = a[4] = 0;
  l = strlen(s);
  if (l % 2 == 0) {
    for (i = 0; i < l; i++) {
      if (s[i] == 'L') a[1]++;
      if (s[i] == 'R') a[2]++;
      if (s[i] == 'U') a[3]++;
      if (s[i] == 'D') a[4]++;
    }
    p = abs(a[1] - a[2]);
    p2 = abs(a[3] - a[4]);
    if (p <= p2)
      min = p;
    else
      min = p2;
    cout << min + (abs(p - p2)) / 2;
  } else
    cout << "-1";
}
