#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, m = 0;
  cin >> n >> m;
  vector<vector<int>> v(n + 1);
  for (int i = 1; i < n + 1; ++i) {
    if ((i == 1) || (i == n))
      v[i].resize(m + 1);
    else
      v[i].resize(2);
  }
  int fx = 0, fy = 0;
  cin >> fx >> fy;
  int x = fx, y = fy, x0 = 0, y0 = 0;
  int vert, hori;
  for (int i = 0; i < 2; ++i) {
    char c;
    cin >> c;
    switch (c) {
      case 'U':
        vert = -1;
        ;
        break;
      case 'D':
        vert = 1;
        break;
      case 'L':
        hori = -1;
        break;
      case 'R':
        hori = 1;
        break;
    }
  }
  int h0 = hori, v0 = vert;
  long long sum = 1;
  int max = m + n - 2;
  int time = 1;
  v[x][((x == 1) || (x == n)) ? y : y / m] = 1;
  while (true) {
    int dx = 0, dy = 0;
    if (y == 1) hori = 1;
    if (y == m) hori = -1;
    if (x == 1) vert = 1;
    if (x == n) vert = -1;
    dy = (hori == 1) ? (m - y) : (y - 1);
    dx = (vert == 1) ? (n - x) : (x - 1);
    int d = (dx < dy) ? dx : dy;
    x += d * vert;
    y += d * hori;
    sum += d;
    x0 = x;
    y0 = ((x == 1) || (x == n)) ? y : y / m;
    if (v[x0][y0] != 1) {
      ++time;
      v[x0][y0] = 1;
    }
    if ((x == fx) && (y == fy)) {
      if (((x == 1) || (x == n)) && (hori == h0)) break;
      if (((y == 1) || (y == m)) && (vert == v0)) break;
      if (((x == 1) || (x == n)) && ((y == 1) || (y == m))) break;
    }
    if (time == max) break;
  }
  if (time == max)
    cout << sum;
  else
    cout << -1;
}
