#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int horizontal = 0, vertical = 0;
  if (s.length() % 2 > 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < s.length(); i++) {
    if (s.at(i) == 'D') {
      vertical++;
    } else if (s.at(i) == 'U') {
      vertical--;
    } else if (s.at(i) == 'L') {
      horizontal++;
    } else if (s.at(i) == 'R') {
      horizontal--;
    }
  }
  int answer = 0;
  int reminder = 0;
  horizontal = abs(horizontal);
  vertical = abs(vertical);
  answer += horizontal / 2;
  answer += vertical / 2;
  if (horizontal % 2 > 0) {
    reminder++;
  }
  if (vertical % 2 > 0) {
    reminder--;
    answer++;
  }
  cout << answer + reminder << endl;
  return 0;
}
