#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int m[5][1002][1002];
int a[1002][1002];
char str[1005][1005];
bool vis[5][1002][1002];
int f[5][1002][1002];
pair<int, pair<int, int> > q[6000000];
int n, r;
int getsum(char ch) {
  if (ch == '+') return 0;
  if (ch == '-') return 1;
  if (ch == '|') return 2;
  if (ch == '^') return 3;
  if (ch == '>') return 4;
  if (ch == 'v') return 5;
  if (ch == '<') return 6;
  if (ch == 'L') return 7;
  if (ch == 'U') return 8;
  if (ch == 'R') return 9;
  if (ch == 'D') return 10;
  return 11;
}
bool Left(int x) {
  if (x == 0 || x == 1 || x == 6 || (x >= 7 && x <= 10 && x != 7)) return true;
  return false;
}
bool Right(int x) {
  if (x == 0 || x == 1 || x == 4 || (x >= 7 && x <= 10 && x != 9)) return true;
  return false;
}
bool Up(int x) {
  if (x == 0 || x == 2 || x == 3 || (x >= 7 && x <= 10 && x != 8)) return true;
  return false;
}
bool Down(int x) {
  if (x == 0 || x == 2 || x == 5 || (x >= 7 && x <= 10 && x != 10)) return true;
  return false;
}
int trans(int x) {
  if (x == 0) return 0;
  if (x <= 2) return 3 - x;
  if (x <= 5) return x + 1;
  if (x == 6) return 3;
  if (x <= 9) return x + 1;
  if (x == 10) return 7;
  return 11;
}
bool check(int type, int x, int y, int id) {
  if (id == 0) {
    int xx = m[type][x][y], yy = m[type][x][y + 1];
    if (Right(xx) && Left(yy)) return true;
    return false;
  }
  if (id == 1) {
    int xx = m[type][x][y], yy = m[type][x][y - 1];
    if (Left(xx) && Right(yy)) return true;
    return false;
  }
  if (id == 2) {
    int xx = m[type][x][y], yy = m[type][x + 1][y];
    if (Down(xx) && Up(yy)) return true;
    return false;
  }
  if (id == 3) {
    int xx = m[type][x][y], yy = m[type][x - 1][y];
    if (Up(xx) && Down(yy)) return true;
    return false;
  }
}
int main() {
  int sx, sy, tx, ty;
  scanf("%d %d", &n, &r);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= r; j++) a[i][j] = getsum(str[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= r; j++) {
      m[0][i][j] = a[i][j];
      for (int k = 1; k <= 3; k++) m[k][i][j] = trans(m[k - 1][i][j]);
    }
  memset(f, 0x3f, sizeof(f));
  scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
  int h = 0, t = 1;
  q[t] = make_pair(0, make_pair(sx, sy));
  vis[0][sx][sy] = true;
  f[0][sx][sy] = 0;
  while (h < t) {
    pair<int, pair<int, int> > k = q[++h];
    int type = k.first, x = k.second.first, y = k.second.second;
    if (type == 3 && x == 1 && y == 1) {
      type++;
      type--;
    }
    for (int i = 0; i < 4; i++) {
      int xx = x + d[i][0], yy = y + d[i][1];
      if (xx < 1 || yy < 1 || xx > n || yy > r) continue;
      if (vis[type][xx][yy]) continue;
      if (check(type, x, y, i) == false) continue;
      vis[type][xx][yy] = true;
      q[++t] = make_pair(type, make_pair(xx, yy));
      f[type][xx][yy] = f[type][x][y] + 1;
    }
    int ntype = (type + 1) % 4;
    if (vis[ntype][x][y]) continue;
    vis[ntype][x][y] = true;
    q[++t] = make_pair(ntype, make_pair(x, y));
    f[ntype][x][y] = f[type][x][y] + 1;
  }
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < 4; i++) ans = min(ans, f[i][tx][ty]);
  if (ans == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
