#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return SQR(POW(B, P / 2));
}
template <class T>
inline T BMOD(T p, T e, T m) {
  T ret = 1;
  while (e) {
    if (e & 1) ret = (ret * p) % m;
    p = (p * p) % m;
    e >>= 1;
  }
  return (T)ret;
}
template <typename T>
inline T ModInv(T b, T m) {
  return BMOD(b, m - 2, m);
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
string s;
int main() {
  int x = 100000, y = 100000;
  cin >> s;
  int sz = s.size();
  int res = 100000000;
  int nu = 0, nd = 0, nl = 0, nr = 0;
  for (int i = 0; i < s.size(); i++) {
    int baki = sz - (i + 1);
    if (s[i] == 'U')
      nu++;
    else if (s[i] == 'D')
      nd++;
    else if (s[i] == 'L')
      nl++;
    else if (s[i] == 'R')
      nr++;
  }
  if (sz % 2 != 0) {
    printf("%d", -1), puts("");
  } else {
    int ans = 0;
    int x = min(nu, nd);
    int baki = abs(nu - x) + abs(x - nd);
    x = min(nl, nr);
    int rest = abs(nl - x) + abs(nr - x);
    x = min(baki, rest);
    ans = x;
    baki -= x;
    rest -= x;
    ans += (baki / 2);
    ans += (rest / 2);
    printf("%d", ans), puts("");
  }
  return 0;
}
