#include <bits/stdc++.h>
using namespace std;
int arr[1000];
int main() {
  string S;
  cin >> S;
  if (S.length() % 2 == 1) {
    cout << "-1" << endl;
    return 0;
  }
  for (long long int i = (0); i < (S.length()); ++i) {
    arr[S[i]]++;
  }
  long long int fir = abs(arr['R'] - arr['L']);
  long long int sec = abs(arr['U'] - arr['D']);
  cout << (fir + sec) / 2 << endl;
  return 0;
}
