#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int inf = 1e7;
const int MAXM = 3e5 + 5;
const int MAXN = 1e6 + 4;
map<char, int> m;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    m[s[i]]++;
  }
  int p1 = abs(m['U'] - m['D']);
  int p2 = abs(m['R'] - m['L']);
  if (p1 == p2) {
    cout << p1 << endl;
  } else {
    if ((p1 + p2) % 2 == 0) {
      cout << (p1 + p2) / 2 << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
