#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  string s;
  cin >> s;
  if (s.length() % 2 != 0)
    printf("-1");
  else {
    int r = 0, l = 0, u = 0, d = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'R')
        r++;
      else if (s[i] == 'U')
        u++;
      else if (s[i] == 'D')
        d++;
      else
        l++;
    }
    if (r < l) swap(r, l);
    if (u < d) swap(u, d);
    if (abs(r - l) % 2 == 0) {
      cout << abs(r - ((r + l) / 2)) + abs(d - ((d + u) / 2));
    } else {
      if (r == l)
        cout << u - d;
      else
        cout << r - (((r - (u - d)) + l) / 2);
    }
  }
  return 0;
}
