#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
char s[N];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L')
      x--;
    else if (s[i] == 'R')
      x++;
    else if (s[i] == 'U')
      y++;
    else
      y--;
  }
  if ((abs(x) + abs(y)) % 2 == 0)
    cout << (abs(x) + abs(y)) / 2 << endl;
  else
    cout << -1 << endl;
}
