#include <bits/stdc++.h>
int n;
char s[100005];
int abs(int x) {
  if (x < 0) return -x;
  return x;
}
int main() {
  int i, x, y;
  scanf(" %s", s);
  n = strlen(s);
  if (n % 2 != 0)
    printf("-1");
  else {
    x = y = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == 'L') x--;
      if (s[i] == 'R') x++;
      if (s[i] == 'U') y++;
      if (s[i] == 'D') y--;
    }
    printf("%d", (abs(x) + abs(y)) / 2);
  }
}
