#include <bits/stdc++.h>
using namespace std;
const double inf = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int u = 0, r = 0;
  string t;
  cin >> t;
  string c;
  for (long long i = 0; i < t.length(); i++) {
    c = t[i];
    if (c == "U") {
      u++;
    } else if (c == "D") {
      u--;
    } else if (c == "L") {
      r++;
    } else {
      r--;
    }
  }
  if (u % 2 == 0 && r % 2 == 0) {
    cout << abs(u) / 2 + abs(r) / 2 << endl;
  } else if (u % 2 != 0 && r % 2 != 0) {
    cout << (abs(u) + 1) / 2 + (abs(r) - 1) / 2 << endl;
  } else {
    cout << -1 << endl;
  }
}
