#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  long long int a, b, c, d, e, g, h, l, m, n, o, p, q, s, r, t, u, v, w, x, y,
      z;
  long long int i, j, ct = 0, f = 0, k = 0, max = 0, min = 999999999999999999;
  long long int A, B, C, D, E, F, G, H, J, K, L, M, N, O, P, Q, R, S, T, U, V,
      W, X, Y, Z;
  char ch, ch1, ch2;
  double d1, d2, d3;
  string st, st1;
  map<string, int> ma;
  vector<int> ve, ve1;
  vector<int>::iterator I;
  cin >> st;
  int ar[90] = {0};
  l = st.size();
  if (l % 2) {
    cout << -1;
    return 0;
    ;
  }
  for (i = 0; i < l; i++) {
    ar[st[i]]++;
  }
  a = ar[68];
  b = ar[76];
  c = ar[82];
  d = ar[85];
  if (a >= d) {
    e = (a + d) / 2;
    a = a - e;
    k = k + a;
    d = d + a;
    f = d - e;
    if (b > c) {
      c = c + f;
      f = (c + b) / 2;
      k = k + (b - f);
    } else {
      b = b + f;
      f = (c + b) / 2;
      k = k + (c - f);
    }
  } else {
    e = (a + d) / 2;
    d = d - e;
    k = k + d;
    a = a + d;
    f = a - e;
    if (b > c) {
      c = c + f;
      f = (c + b) / 2;
      k = k + (b - f);
    } else {
      b = b + f;
      f = (c + b) / 2;
      k = k + (c - f);
    }
  }
  cout << k;
  return 0;
  ;
}
