#include <bits/stdc++.h>
using namespace std;
int const N = 1010;
int g[4][N][N];
char mp[N][N];
int n, m;
int sx, sy, dx, dy;
int dir[4][2] = {1, 0, 0, -1, -1, 0, 0, 1};
int f[128];
struct Node {
  int x, y, d;
  Node(int x = 0, int y = 0, int d = 0) : x(x), y(y), d(d) {}
} tmp;
queue<Node> q;
int dp[4][N][N];
bool ck(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
void upd(int x, int y, int d, int tx, int ty, int td) {
  if (!ck(tx, ty)) return;
  if (dp[td][tx][ty] > dp[d][x][y] + 1) {
    dp[td][tx][ty] = dp[d][x][y] + 1;
    q.push(Node(tx, ty, td));
  }
}
int main() {
  f['+'] = 15, f['-'] = 10, f['|'] = 5, f['^'] = 4, f['>'] = 8, f['<'] = 2;
  f['v'] = 1, f['L'] = 13, f['R'] = 7, f['U'] = 11, f['D'] = 14, f['*'] = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); ++i) scanf(" %s", mp[i]);
  scanf("%d%d%d%d", &sx, &sy, &dx, &dy);
  --sx, --sy, --dx, --dy;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      int t = f[mp[i][j]];
      for (int k = 0; k < (4); ++k) {
        g[k][i][j] = t;
        t = (t & 1) << 3 | (t >> 1);
      }
    }
  }
  memset(dp, (0x3f), sizeof dp);
  dp[0][sx][sy] = 0;
  q.push(Node(sx, sy, 0));
  while (!q.empty()) {
    tmp = q.front();
    q.pop();
    int x = tmp.x, y = tmp.y, d = tmp.d;
    upd(x, y, d, x, y, (d + 3) % 4);
    for (int i = 0; i < (4); ++i) {
      if (g[d][x][y] >> i & 1) {
        int op = i ^ 2, tx = x + dir[i][0], ty = y + dir[i][1];
        if (ck(tx, ty) && (g[d][tx][ty] >> op & 1)) {
          upd(x, y, d, x + dir[i][0], y + dir[i][1], d);
        }
      }
    }
  }
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < (4); ++i) ans = min(ans, dp[i][dx][dy]);
  if (ans == 0x3f3f3f3f) ans = -1;
  printf("%d\n", ans);
  return 0;
}
