#include <bits/stdc++.h>
char s[1000000];
using namespace std;
int main() {
  int l, a = 0, b = 0, i;
  cin >> s;
  l = strlen(s);
  if (l % 2 == 0) {
    for (i = 0; i < l; i++) {
      if (s[i] == 'U')
        a++;
      else if (s[i] == 'D')
        a--;
      else if (s[i] == 'R')
        b++;
      else if (s[i] == 'L')
        b--;
    }
    a = abs(a);
    b = abs(b);
    if ((a + b) % 2 == 0)
      cout << ((a + b) / 2);
    else
      cout << "-1";
  } else
    cout << "-1";
}
