#include <bits/stdc++.h>
using namespace std;
const long long infi = 1000000000000000009;
char str[100009];
int main() {
  int i, j, n;
  scanf("%s", str);
  n = strlen(str);
  int l = 0, r = 0, u = 0, d = 0;
  for (i = 0; i < n; i++) {
    if (str[i] == 'L') l++;
    if (str[i] == 'R') r++;
    if (str[i] == 'U') u++;
    if (str[i] == 'D') d++;
  }
  if (n % 2 == 0) {
    int d1 = abs(l - r);
    int d2 = abs(u - d);
    int ans = min(d1, d2) + abs(d1 - d2) / 2;
    printf("%d\n", ans);
  } else
    printf("-1\n");
  return 0;
}
