#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, cnt3, cnt4;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < ((int)s.size()); i++) {
    if (s[i] == 'L')
      cnt1++;
    else if (s[i] == 'R')
      cnt2++;
    else if (s[i] == 'U')
      cnt3++;
    else
      cnt4++;
  }
  if (((int)s.size()) % 2 == 1)
    cout << "-1" << endl;
  else {
    if (abs(cnt1 - cnt2) % 2 == 0) {
      cout << (abs(cnt1 - cnt2) / 2 + abs(cnt3 - cnt4) / 2) << endl;
    } else {
      cout << (abs(cnt1 - cnt2) / 2 + abs(cnt3 - cnt4) / 2) + 1 << endl;
    }
  }
  return 0;
}
