#include <bits/stdc++.h>
using namespace std;
int main() {
  int x = 0, xx = 0, y = 0, yy = 0;
  string st;
  cin >> st;
  for (int i = 0; i < st.length(); i++) {
    if (st[i] == 'L') {
      x--;
      xx++;
    }
    if (st[i] == 'R') {
      x++;
      xx++;
    }
    if (st[i] == 'U') {
      y++;
      yy++;
    }
    if (st[i] == 'D') {
      y--;
      yy++;
    }
  }
  y = abs(y);
  x = abs(x);
  int t = abs(x - y);
  if (t % 2 == 1) {
    cout << "-1\n";
  } else {
    int tmp;
    if (x >= y) {
      tmp = x - y;
      tmp /= 2;
      tmp += y;
    } else {
      tmp = y - x;
      tmp /= 2;
      tmp += x;
    }
    cout << tmp << endl;
  }
  return 0;
}
