#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[100009], c;
  long long int d = 0, l = 0, u = 0, r = 0, x, z, i, y;
  scanf("%s", a);
  if (strlen(a) % 2 == 1) {
    cout << "-1" << endl;
    return 0;
  }
  for (i = 0; a[i] != '\0'; i++) {
    if (a[i] == 'L') l++;
    if (a[i] == 'D') d++;
    if (a[i] == 'R') r++;
    if (a[i] == 'U') u++;
  }
  x = abs(l - r) / 2;
  z = abs(l - r) % 2;
  y = abs(u - d) / 2;
  cout << x + y + z << endl;
}
