#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 9;
const int inf = 1e8 + 9;
int n, m;
char mapp[maxn][maxn];
int sx, sy, ex, ey;
int use[maxn][maxn][5];
bool flag[maxn][maxn][5];
int dirx[4] = {0, 1, 0, -1}, diry[4] = {1, 0, -1, 0};
struct II {
  int x, y, t, move;
};
queue<II> aha;
int bfs();
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; i++) scanf("%s", mapp[i]);
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    sx--, sy--, ex--, ey--;
    for (int i = 0; i < maxn; i++)
      for (int j = 0; j < maxn; j++)
        for (int k = 0; k < 4; k++) use[i][j][k] = inf;
    memset(flag, 0, sizeof(flag));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        char x = mapp[i][j];
        if (x == '+' || x == '-' || x == '>' || x == 'U' || x == 'L' ||
            x == 'D')
          flag[i][j][0] = 1;
        if (x == '+' || x == '|' || x == '^' || x == 'L' || x == 'D' ||
            x == 'R')
          flag[i][j][3] = 1;
        if (x == '+' || x == '-' || x == '<' || x == 'D' || x == 'R' ||
            x == 'U')
          flag[i][j][2] = 1;
        if (x == '+' || x == '|' || x == 'v' || x == 'R' || x == 'U' ||
            x == 'L')
          flag[i][j][1] = 1;
      }
    }
    int ans = bfs();
    printf("%d\n", ans);
  }
  return 0;
}
int bfs() {
  while (!aha.empty()) aha.pop();
  use[sx][sy][0] = 0;
  II fir;
  fir.x = sx, fir.y = sy, fir.t = 0, fir.move = 0;
  aha.push(fir);
  int f = -1;
  while (!aha.empty()) {
    II tp = aha.front();
    aha.pop();
    if (tp.x == ex && tp.y == ey) {
      f = tp.t;
      break;
    }
    II go = tp;
    if (go.t + 1 < use[go.x][go.y][(go.move + 1) % 4]) {
      use[go.x][go.y][(go.move + 1) % 4] = go.t + 1;
      go.move += 1, go.t += 1;
      go.move %= 4;
      aha.push(go);
    }
    for (int i = 0; i < 4; i++) {
      go = tp;
      int nx = tp.x + dirx[i], ny = tp.y + diry[i];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
      if (flag[tp.x][tp.y][(i - tp.move + 4) % 4] == 0 ||
          flag[nx][ny][(i - tp.move + 2 + 4) % 4] == 0)
        continue;
      go.x = nx, go.y = ny, go.t += 1, go.move %= 4;
      if (use[go.x][go.y][go.move] <= go.t) continue;
      aha.push(go);
      use[go.x][go.y][go.move] = go.t;
    }
  }
  return f;
}
