#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S.size() % 2 == 1) {
    cout << -1;
    return 0;
  }
  int x = 0;
  int y = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'U') {
      y--;
    } else if (S[i] == 'D') {
      y++;
    } else if (S[i] == 'L') {
      x--;
    } else {
      x++;
    }
  }
  cout << (abs(x) + abs(y)) / 2;
  return 0;
}
