#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.size() % 2) {
    cout << -1 << endl;
    return 0;
  }
  int dist = 0;
  int curri = 0, currj = 0;
  for (const char c : s) {
    switch (c) {
      case 'L':
        currj -= 1;
        break;
      case 'R':
        currj += 1;
        break;
      case 'U':
        curri -= 1;
        break;
      case 'D':
        curri += 1;
        break;
    }
  }
  dist = abs(curri) + abs(currj);
  cout << dist / 2 << endl;
  return 0;
}
