#include <bits/stdc++.h>
using namespace std;
int m, n;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
char maze[1005][1005];
int vis[1005][1005][4];
bool ss[1005][1005][4];
struct node {
  int x, y, tim, num;
  friend bool operator<(node a, node b) {
    if (a.num != b.num)
      return a.num < b.num;
    else
      return a.tim < b.tim;
  }
};
int judge(int x, int y) {
  if (x < 0 | x >= n || y < 0 || y >= m) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(ss, 0, sizeof(ss));
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) {
    scanf("%s", maze[i]);
    for (int j = 0; j < m; j++) {
      if (maze[i][j] == '+')
        ss[i][j][0] = ss[i][j][1] = ss[i][j][2] = ss[i][j][3] = 1;
      if (maze[i][j] == '-') ss[i][j][1] = ss[i][j][3] = 1;
      if (maze[i][j] == '|') ss[i][j][0] = ss[i][j][2] = 1;
      if (maze[i][j] == '^') ss[i][j][0] = 1;
      if (maze[i][j] == 'v') ss[i][j][2] = 1;
      if (maze[i][j] == '<') ss[i][j][3] = 1;
      if (maze[i][j] == '>') ss[i][j][1] = 1;
      if (maze[i][j] == 'U') ss[i][j][1] = ss[i][j][2] = ss[i][j][3] = 1;
      if (maze[i][j] == 'D') ss[i][j][0] = ss[i][j][1] = ss[i][j][3] = 1;
      if (maze[i][j] == 'L') ss[i][j][0] = ss[i][j][1] = ss[i][j][2] = 1;
      if (maze[i][j] == 'R') ss[i][j][0] = ss[i][j][3] = ss[i][j][2] = 1;
    }
  }
  int x1, y1, x2, y2, ans = 0;
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  x1--;
  x2--;
  y1--;
  y2--;
  queue<node> q;
  node st, buf;
  st.x = x1;
  st.y = y1;
  st.tim = 0;
  st.num = 0;
  vis[x1][y1][0] = 1;
  q.push(st);
  while (!q.empty()) {
    st = q.front();
    q.pop();
    if (st.x == x2 && st.y == y2) {
      ans = st.num;
      cout << ans << endl;
      return 0;
    }
    int tn = st.tim;
    for (int i = 0; i < 4; i++) {
      int bx = st.x + dx[i];
      int by = st.y + dy[i];
      if (judge(bx, by) == 0) continue;
      int js = i;
      if (vis[bx][by][tn] == 1) continue;
      if (ss[st.x][st.y][(js + 3 * tn) % 4] &&
          ss[bx][by][(js + 2 + 3 * tn) % 4]) {
        buf.x = bx;
        buf.y = by;
        buf.tim = tn;
        buf.num = st.num + 1;
        q.push(buf);
        vis[bx][by][tn] = 1;
      }
    }
    int nn = (tn + 1) % 4;
    if (!vis[st.x][st.y][nn]) {
      vis[st.x][st.y][nn] = 1;
      buf.x = st.x;
      buf.y = st.y;
      buf.tim = nn;
      buf.num = st.num + 1;
      q.push(buf);
    }
  }
  cout << -1 << endl;
}
