#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, m, n, x, y, z, p, q;
  string str;
  cin >> str;
  n = str.length();
  if (n % 2 == 0) {
    int l = 0, r = 0, u = 0, d = 0;
    for (i = 0; i < n; i++) {
      if (str[i] == 'L') {
        l++;
      } else if (str[i] == 'R') {
        r++;
      } else if (str[i] == 'U') {
        u++;
      } else {
        d++;
      }
    }
    p = abs(u - d);
    q = abs(l - r);
    int avg1 = (u + d) / 2;
    int avg2 = (l + r) / 2;
    int ans = 0;
    ans = ans + avg1 - min(u, d);
    ans = ans + avg2 - min(l, r);
    if ((avg1 * 2) != (u + d)) {
      ans = ans + 1;
    }
    cout << ans;
  } else {
    cout << "-1";
  }
}
