#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
long long dis[4][maxn][maxn];
int h[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int g[maxn][maxn][4];
int n, m, x1, yy1, x2, y2;
bool mark[4][maxn][maxn];
void input() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char ch;
      cin >> ch;
      if (ch == '+') g[i][j][0] = g[i][j][1] = g[i][j][2] = g[i][j][3] = 1;
      if (ch == '-') g[i][j][1] = g[i][j][3] = 1;
      if (ch == '|') g[i][j][0] = g[i][j][2] = 1;
      if (ch == '^') g[i][j][0] = 1;
      if (ch == '>') g[i][j][1] = 1;
      if (ch == 'v') g[i][j][2] = 1;
      if (ch == '<') g[i][j][3] = 1;
      if (ch == 'L') g[i][j][0] = g[i][j][1] = g[i][j][2] = 1;
      if (ch == 'R') g[i][j][0] = g[i][j][3] = g[i][j][2] = 1;
      if (ch == 'U') g[i][j][3] = g[i][j][1] = g[i][j][2] = 1;
      if (ch == 'D') g[i][j][0] = g[i][j][1] = g[i][j][3] = 1;
    }
  cin >> x1 >> yy1 >> x2 >> y2;
  x1--, yy1--, x2--, y2--;
}
bool is_valid(int x, int y) {
  if (x < n && x >= 0 && y < m && y >= 0) return true;
  return false;
}
bool valid(int x, int y, int a, int b, int t, int k) {
  int tmp = k - t, tmp2 = ((k ^ 2) - t);
  if (tmp < 0) tmp += 4;
  if (tmp2 < 0) tmp2 += 4;
  return (g[x][y][tmp] && g[a][b][tmp2]);
}
void bfs() {
  queue<pair<pair<int, int>, int> > q;
  q.push({{x1, yy1}, 0});
  mark[0][x1][yy1] = true;
  dis[0][x1][yy1] = 0;
  while (!q.empty()) {
    int x = q.front().first.first, y = q.front().first.second,
        t = q.front().second;
    q.pop();
    for (int k = 0; k < 4; k++) {
      int a = x + h[k][0], b = y + h[k][1];
      if (is_valid(a, b) && !mark[t][a][b]) {
        if (valid(x, y, a, b, t, k)) {
          dis[t][a][b] = dis[t][x][y] + 1;
          q.push({{a, b}, t});
          mark[t][a][b] = true;
        }
      }
    }
    int tt = (t + 1) % 4;
    if (!mark[tt][x][y] || dis[tt][x][y] > dis[t][x][y]) {
      mark[tt][x][y] = true;
      q.push({{x, y}, tt});
      dis[tt][x][y] = dis[t][x][y] + 1;
    }
  }
}
void init() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int k = 0; k < 4; k++) dis[k][i][j] = 1e9;
}
int main() {
  input();
  init();
  bfs();
  long long ans = 1e9;
  for (int i = 0; i < 4; i++)
    if (dis[i][x2][y2] != -1) ans = min(ans, dis[i][x2][y2]);
  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
