#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
char str[N];
int main(int argc, char *argv[]) {
  scanf("%s", str);
  int u = 0, d = 0, l = 0, r = 0, n = strlen(str);
  for (int i = 0; i < n; ++i)
    if (str[i] == 'U')
      ++u;
    else if (str[i] == 'D')
      ++d;
    else if (str[i] == 'L')
      ++l;
    else
      ++r;
  int ans = 0;
  if (d != u) {
    if (d > u) swap(d, u);
    ans += (u - d) / 2;
    d += ans;
    u -= ans;
  }
  if (l != r) {
    if (r > l) swap(l, r);
    int t = (l - r) / 2;
    ans += t;
    l -= t;
    r += t;
  }
  if (l == r && u == d)
    printf("%d\n", ans);
  else if (l != r && u != d)
    printf("%d\n", ans + 1);
  else
    printf("-1\n");
  return 0;
}
