#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m, sx, sy;
char dir[4];
int main() {
  scanf("%d%d%d%d %s", &n, &m, &sx, &sy, dir);
  int dx = dir[0] == 'U' ? -1 : 1;
  int dy = dir[1] == 'L' ? -1 : 1;
  int remain = n + m - 2;
  set<pair<int, int> > Set;
  if (sx == 1 || sx == n || sy == 1 || sy == m) {
    remain--;
    Set.insert({sx, sy});
  }
  long long ans = 0;
  for (int i = (0); i < (4 * N); ++i) {
    int step = (1ll << (30));
    step = min(step, dx == 1 ? n - sx : sx - 1);
    step = min(step, dy == 1 ? m - sy : sy - 1);
    ans += step;
    sx += dx * step;
    sy += dy * step;
    if ((sx == 1 && dx == -1) || (sx == n && dx == 1)) dx *= -1;
    if ((sy == 1 && dy == -1) || (sy == m && dy == 1)) dy *= -1;
    if (Set.find({sx, sy}) == Set.end()) {
      if (!--remain) {
        printf("%lld\n", ans + 1);
        return 0;
      }
      Set.insert({sx, sy});
    }
  }
  puts("-1");
  return 0;
}
