#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  int r = 0, l = 0, d = 0, u = 0;
  cin >> str;
  if (str.length() % 2 == 0) {
    for (int i = 0; i < str.length(); i++) {
      if (str[i] == 'L') {
        l++;
      }
      if (str[i] == 'R') {
        r++;
      }
      if (str[i] == 'U') {
        u++;
      }
      if (str[i] == 'D') {
        d++;
      }
    }
    if (l > r)
      l = l - r, r = 0;
    else
      r = r - l, l = 0;
    if (u > d)
      u = u - d, d = 0;
    else
      d = d - u, u = 0;
    int v1 = 0, v2 = 0;
    v1 = max(l, max(r, max(u, d)));
    if (v1 == l)
      l = -10;
    else if (v1 == r)
      r = -10;
    else if (v1 == u)
      u = -10;
    else if (v1 == d)
      d = -10;
    v2 = max(l, max(r, max(u, d)));
    printf("%d\n", v2 + (v1 - v2) / 2);
  } else
    printf("-1\n");
}
