#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  char c;
  int u = 0, l = 0, d = 0, r = 0;
  while (cin >> c) {
    switch (c) {
      case 'U':
        u++;
        break;
      case 'L':
        l++;
        break;
      case 'D':
        d++;
        break;
      case 'R':
        r++;
        break;
    }
  }
  double k = 0;
  if ((u + l + d + r) % 2 != 0) {
    cout << "-1";
    return 0;
  } else {
    k += abs(u - d);
    k += abs(r - l);
  }
  cout << k / 2;
}
