#include <bits/stdc++.h>
using namespace std;
struct debugger {
  static void call(const char* it) {}
  template <typename T, typename... valT>
  static void call(const char* it, T val, valT... rest) {
    string var = "";
    for (; *it && *it != ','; it++)
      if (*it != ' ') var += *it;
    cout << var << '=' << val << ' ';
    call(++it, rest...);
  }
};
const double PI = acos(-1.0);
const int MOD = 1e7 + 7;
const int MAX = 1e5 + 2;
int main() {
  string s;
  cin >> s;
  if (s.size() & 1)
    puts("-1");
  else {
    int x = 0, y = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'L')
        x--;
      else if (s[i] == 'R')
        x++;
      else if (s[i] == 'U')
        y++;
      else
        y--;
    }
    printf("%d\n", (int)(abs(x) + abs(y)) / 2);
  }
  return 0;
}
