#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[10000007];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long int cnt = 0, a = 0, b = 0;
  map<char, long long int> cou;
  if (s.size() % 2 != 0) {
    cout << "-1" << endl;
    return 0;
  } else {
    for (long long int i = 0; i < s.size(); i++) {
      if (s[i] == 'L') a--;
      if (s[i] == 'R') a++;
      if (s[i] == 'U') b++;
      if (s[i] == 'D') b--;
    }
  }
  cnt = (abs(a) + abs(b)) / 2;
  cout << cnt;
  return 0;
}
