#include <bits/stdc++.h>
using namespace std;
int i, n, m, k, l, x, y, ans;
string s;
int main() {
  cin >> s;
  if (s.length() % 2 != 0) {
    cout << "-1";
    return 0;
  }
  for (i = 0; i < s.length(); i++) {
    if (s[i] == 'L') x--;
    if (s[i] == 'R') x++;
    if (s[i] == 'U') y++;
    if (s[i] == 'D') y--;
  }
  ans += abs(x / 2) + abs(y / 2) + ((x % 2 != 0 || y % 2 != 0) ? 1 : 0);
  cout << ans;
}
