#include <bits/stdc++.h>
using namespace std;
int a[4];
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  string str;
  cin >> str;
  if (str.size() & 1) {
    cout << -1 << endl;
    return 0;
  }
  for (char &c : str) {
    switch (c) {
      case 'U':
        ++a[0];
        break;
      case 'D':
        ++a[1];
        break;
      case 'L':
        ++a[2];
        break;
      case 'R':
        ++a[3];
        break;
    }
  }
  int mn = *min_element(a, a + 4);
  for (int &i : a) i -= mn;
  cout << abs(a[0] - a[1]) / 2 + abs(a[2] - a[3]) / 2 + ((a[0] + a[1]) & 1)
       << endl;
}
