#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int int_inf = 0x3f3f3f3f;
const long long ll_inf = 0x3f3f3f3f3f3f3f3f;
const int INT_INF = (int)((1ll << 31) - 1);
const double double_inf = 1e30;
const double eps = 1e-14;
inline int readint() {
  int x;
  scanf("%d", &x);
  return x;
}
inline int readstr(char *s) {
  scanf("%s", s);
  return strlen(s);
}
class cmpt {
 public:
  bool operator()(const int &x, const int &y) const { return x > y; }
};
int Rand(int x, int o) {
  if (!x) return 0;
  int tem = (int)((double)rand() / RAND_MAX * x) % x;
  return o ? tem + 1 : tem;
}
long long ll_rand(long long x, int o) {
  if (!x) return 0;
  long long tem = (long long)((double)rand() / RAND_MAX * x) % x;
  return o ? tem + 1 : tem;
}
void data_gen() {
  srand(time(0));
  freopen("in.txt", "w", stdout);
  int kases = 10;
  printf("%d\n", kases);
  while (kases--) {
    long long sz = 100000;
    printf("%d\n", sz);
    for (int i = (1); i <= (sz); i++) {
      int o = Rand(2, 0);
      int x = Rand(1e9, 1);
      int y1 = Rand(1e9, 1), y2 = Rand(1e9, 1);
      if (o == 0)
        printf("%d %d %d %d\n", x, y1, x, y1);
      else
        printf("%d %d %d %d\n", y1, x, y2, x);
    }
  }
}
const int maxn = 1e5 + 10;
char s[maxn];
int main() {
  int debug = 0;
  if (debug) freopen("in.txt", "r", stdin);
  while (~scanf("%s", s)) {
    int x[4];
    int len = strlen(s);
    memset(x, (0), sizeof(x));
    for (int i = (0); i <= (len - 1); i++)
      x[0] += s[i] == 'U', x[1] += s[i] == 'D', x[2] += s[i] == 'L',
          x[3] += s[i] == 'R';
    int X = abs(x[0] - x[1]), Y = abs(x[2] - x[3]);
    int tot = X + Y;
    int ans = -1;
    if (tot % 2 == 0) ans = tot >> 1;
    printf("%d\n", ans);
  }
  return 0;
}
