#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2, typename T3>
struct triple {
  T1 a;
  T2 b;
  T3 c;
  triple() : a(T1()), b(T2()), c(T3()){};
  triple(T1 _a, T2 _b, T3 _c) : a(_a), b(_b), c(_c) {}
};
template <typename T1, typename T2, typename T3>
bool operator<(const triple<T1, T2, T3> &t1, const triple<T1, T2, T3> &t2) {
  if (t1.a != t2.a)
    return t1.a < t2.a;
  else if (t1.b != t2.b)
    return t1.b < t2.b;
  else
    return t1.c < t2.c;
}
using namespace std;
void solve() {
  long long n, m, k, x, q, y, z, ct = 0, sum = 0, prev = 0;
  string s;
  bool f = false;
  cin >> s;
  if (s.length() & 1)
    cout << -1 << endl;
  else {
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'U')
        ct++;
      else if (s[i] == 'D')
        ct--;
      else if (s[i] == 'L')
        sum--;
      else
        sum++;
    }
    cout << (abs(sum) + abs(ct)) / 2;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
