#include <bits/stdc++.h>
using namespace std;
char str[100001];
int main() {
  int t1 = 0, t2 = 0, len, ans = 0;
  cin >> str;
  len = strlen(str);
  for (int i = 0; i < len; i++) {
    if (str[i] == 'L')
      t1--;
    else if (str[i] == 'R')
      t1++;
    else if (str[i] == 'U')
      t2++;
    else
      t2--;
  }
  ans = abs(t1) + abs(t2);
  if (ans % 2 == 0)
    cout << (ans / 2);
  else
    cout << -1;
  return 0;
}
