#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> s;
  int n = s.size();
  if (n & 1)
    cout << -1 << endl;
  else {
    int x = 0, y = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'L') x--;
      if (s[i] == 'R') x++;
      if (s[i] == 'U') y++;
      if (s[i] == 'D') y--;
    }
    cout << (abs(x) + abs(y)) / 2 << endl;
  }
  return 0;
}
