#include <bits/stdc++.h>
using namespace std;
int c[1000005];
int main() {
  int i, j, n, cnt, cnt2;
  char s[1000009];
  cin >> s;
  if (strlen(s) % 2)
    printf("-1");
  else {
    for (i = 0; s[i]; i++) {
      c[s[i]]++;
    }
    cnt = abs(c['R'] - c['L']);
    cnt2 = abs(c['U'] - c['D']);
    if (cnt == cnt2)
      printf("%d\n", cnt);
    else
      printf("%d\n", (cnt + cnt2) / 2);
  }
  return 0;
}
