#include <bits/stdc++.h>
using namespace std;
string s;
int l, r, u, d;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); ++i)
    if (s[i] == 'L')
      l++;
    else if (s[i] == 'R')
      r++;
    else if (s[i] == 'U')
      u++;
    else
      d++;
  d = fabs(d - u);
  l = fabs(r - l);
  if (d != l) {
    int val = min(d, l), s = max(d, l) - min(d, l);
    if (s % 2 == 1)
      cout << -1;
    else
      cout << val + s / 2;
  } else
    cout << d;
  return 0;
}
