#include <bits/stdc++.h>
using namespace std;
struct Est {
  int x, y, r;
  Est() {}
  Est(int X, int Y, int R) {
    x = X;
    y = Y;
    r = R;
  }
};
int R, C;
char G[1000][1000];
int dist[1000][1000][4];
Est p[1000][1000][4];
int opposite(int d) { return (d + 2) % 4; }
bool isOpen(Est u, int d) {
  int x = u.x;
  int y = u.y;
  int r = u.r;
  if (x < 0 || x >= R) return false;
  if (y < 0 || y >= C) return false;
  char g = G[x][y];
  if (g == '|' && r % 2 == 1)
    g = '-';
  else if (g == '-' && r % 2 == 1)
    g = '|';
  if (g == '^') return (r == d);
  if (g == '>') return ((r + 1 + 4) % 4 == d);
  if (g == 'v') return ((r + 2 + 4) % 4 == d);
  if (g == '<') return ((r + 3 + 4) % 4 == d);
  if (g == 'U') return (r != d);
  if (g == 'R') return ((r + 1 + 4) % 4 != d);
  if (g == 'D') return ((r + 2 + 4) % 4 != d);
  if (g == 'L') return ((r + 3 + 4) % 4 != d);
  if (g == '*') return false;
  if (g == '+') return true;
  if (g == '-') {
    if (d == 1 || d == 3)
      return true;
    else
      return false;
  }
  if (g == '|') {
    if (d == 1 || d == 3)
      return false;
    else
      return true;
  }
}
void printEst(Est u) { printf("(%d, %d, %d)\n", u.x, u.y, u.r); }
int main() {
  cin >> R >> C;
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      cin >> G[i][j];
      for (int k = 0; k < 4; k++) {
        dist[i][j][k] = -1;
      }
    }
  }
  int sx, sy, ex, ey;
  cin >> sx >> sy;
  sx--;
  sy--;
  cin >> ex >> ey;
  ex--;
  ey--;
  queue<Est> Q;
  dist[sx][sy][0] = 0;
  Q.push(Est(sx, sy, 0));
  int mX[4] = {-1, 0, 1, 0};
  int mY[4] = {0, 1, 0, -1};
  while (!Q.empty()) {
    Est u = Q.front();
    Q.pop();
    if (dist[u.x][u.y][(u.r + 1) % 4] == -1) {
      dist[u.x][u.y][(u.r + 1) % 4] = dist[u.x][u.y][u.r] + 1;
      Q.push(Est(u.x, u.y, (u.r + 1) % 4));
    }
    for (int i = 0; i < 4; i++) {
      Est v(u.x + mX[i], u.y + mY[i], u.r);
      if (isOpen(u, i) && isOpen(v, opposite(i)) && dist[v.x][v.y][v.r] == -1) {
        dist[v.x][v.y][v.r] = dist[u.x][u.y][u.r] + 1;
        p[v.x][v.y][v.r] = u;
        Q.push(v);
      }
    }
  }
  int ans = 1000000000;
  for (int i = 0; i < 4; i++) {
    if (dist[ex][ey][i] == -1) continue;
    ans = min(ans, dist[ex][ey][i]);
  }
  if (ans == 1000000000) ans = -1;
  cout << ans << endl;
}
