#include <bits/stdc++.h>
using namespace std;
struct Cost {
  int a[4];
  int get(int i, int k) { return a[(i - k + 4) % 4]; }
};
char s[1010][1010];
Cost cost[256];
bool vis[1000010][4];
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int n, m;
bool valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
int main() {
  scanf("%d%d", &n, &m);
  cost['+'] = {1, 1, 1, 1};
  cost['-'] = {0, 1, 0, 1};
  cost['|'] = {1, 0, 1, 0};
  cost['^'] = {1, 0, 0, 0};
  cost['>'] = {0, 1, 0, 0};
  cost['v'] = {0, 0, 1, 0};
  cost['<'] = {0, 0, 0, 1};
  cost['L'] = {1, 1, 1, 0};
  cost['R'] = {1, 0, 1, 1};
  cost['U'] = {0, 1, 1, 1};
  cost['D'] = {1, 1, 0, 1};
  cost['*'] = {0, 0, 0, 0};
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  int x0, y0, x1, y1;
  scanf("%d%d%d%d", &x0, &y0, &x1, &y1);
  x0--;
  y0--;
  x1--;
  y1--;
  int source = x0 * m + y0, target = x1 * m + y1;
  memset(vis, 0, sizeof(vis));
  queue<pair<int, int> > q;
  q.push(pair<int, int>(source, 0));
  vis[source][0] = true;
  int level = 0;
  while (!q.empty()) {
    int qsize = q.size();
    while (qsize--) {
      int cur = q.front().first, k = q.front().second;
      if (cur == target) {
        printf("%d\n", level);
        return 0;
      }
      int x = cur / m, y = cur % m;
      q.pop();
      if (!vis[cur][(k + 1) % 4]) {
        vis[cur][(k + 1) % 4] = true;
        q.push(pair<int, int>(cur, (k + 1) % 4));
      }
      for (int d = 0; d < 4; d++) {
        if (cost[s[x][y]].get(d, k) == 1) {
          int x1 = x + dir[d][0], y1 = y + dir[d][1];
          int next = x1 * m + y1;
          if (valid(x1, y1) && cost[s[x1][y1]].get(d + 2, k) == 1 &&
              !vis[next][k]) {
            vis[next][k] = true;
            q.push(pair<int, int>(next, k));
          }
        }
      }
    }
    level++;
  }
  printf("-1\n");
  return 0;
}
