#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  long long int x = 0, y = 0, i, len;
  len = str.length();
  if (len % 2) {
    puts("-1");
    return 0;
  }
  for (i = 0; i < str.length(); ++i) {
    if (str[i] == 'U') y++;
    if (str[i] == 'D') y--;
    if (str[i] == 'R') x++;
    if (str[i] == 'L') x--;
  }
  cout << min(abs(x), abs(y)) + (max(abs(x), abs(y)) - min(abs(x), abs(y))) / 2
       << endl;
}
