#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10, inf = 1e9 + 7;
int n, m, xs, ys, xe, ye, ans;
int Arr[MAXN][MAXN];
pair<int, pair<int, int> > q[MAXN * MAXN * 4];
int ql, qr;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int mark[4][MAXN][MAXN];
bool g(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
int k(int x, int p) { return (((x >> (4 - p)) | (x << p)) & 15); }
bool f(int x, int y, int t, int h) { return (k(Arr[x][y], t) >> h) & 1; }
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < ((int)(s).size()); j++) {
      if (s[j] == '+') Arr[i][j] = 15;
      if (s[j] == '-') Arr[i][j] = 10;
      if (s[j] == '|') Arr[i][j] = 5;
      if (s[j] == '^') Arr[i][j] = 1;
      if (s[j] == '>') Arr[i][j] = 2;
      if (s[j] == 'v') Arr[i][j] = 4;
      if (s[j] == '<') Arr[i][j] = 8;
      if (s[j] == 'U') Arr[i][j] = 14;
      if (s[j] == 'R') Arr[i][j] = 13;
      if (s[j] == 'D') Arr[i][j] = 11;
      if (s[j] == 'L') Arr[i][j] = 7;
    }
  }
  cin >> xs >> ys >> xe >> ye;
  xs--;
  ys--;
  xe--;
  ye--;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < MAXN; j++) fill(mark[i][j], mark[i][j] + MAXN, inf);
  mark[0][xs][ys] = 0;
  q[qr++] = {0, {xs, ys}};
  while (ql < qr) {
    int t, x, y;
    t = q[ql].first;
    tie(x, y) = q[ql++].second;
    if (mark[(t + 1) % 4][x][y] > 1 + mark[t][x][y]) {
      q[qr++] = {(t + 1) % 4, {x, y}};
      mark[(t + 1) % 4][x][y] = 1 + mark[t][x][y];
    }
    for (int i = 0; i < 4; i++) {
      if (!g(x + dx[i], y + dy[i])) continue;
      if (f(x, y, t, i) && f(x + dx[i], y + dy[i], t, (i + 2) % 4) &&
          mark[t][x + dx[i]][y + dy[i]] > 1 + mark[t][x][y]) {
        q[qr++] = {t, {x + dx[i], y + dy[i]}};
        mark[t][x + dx[i]][y + dy[i]] = 1 + mark[t][x][y];
      }
    }
  }
  ans = inf;
  for (int i = 0; i < 4; i++) ans = min(ans, mark[i][xe][ye]);
  if (ans == inf) {
    cout << -1;
    return 0;
  }
  cout << ans << "\n";
  return 0;
}
