#include <bits/stdc++.h>
long long int powermod(long long int _a, long long int _b, long long int _m) {
  long long int _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
using namespace std;
void scan(int &x);
int main(void) {
  char st[100003];
  scanf("%s", st);
  int l = 0, r = 0, u = 0, d = 0;
  int len = strlen(st);
  if (len % 2) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; st[i] != '\0'; i++) {
    if (st[i] == 'L')
      l++;
    else if (st[i] == 'R')
      r++;
    else if (st[i] == 'U')
      u++;
    else
      d++;
  }
  if (l == r && u == d) {
    cout << 0;
    return 0;
  }
  int lim = (l + r + u + d) / 2;
  int ans = 999999999;
  for (int i = 0; i <= lim; i++) {
    ans = min(ans, (abs(((lim - i) - u)) + abs(((lim - i) - d)) + abs(i - l) +
                    abs(i - r)) /
                       2);
  }
  cout << ans;
  return 0;
}
void scan(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
