#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 9;
bool a[MAX][MAX][4];
int dd[MAX][MAX][4];
int n, m, xt, yt, xm, ym;
struct s {
  int x, y, d;
};
queue<s> q;
int f(int k) { return (k % 4 + 4) % 4; }
int xx[4] = {+1, +0, -1, +0}, yy[4] = {+0, -1, +0, +1};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char ch;
      cin >> ch;
      if (ch == '^' || ch == '+' || ch == '|' || ch == 'R' || ch == 'L' ||
          ch == 'D')
        a[i][j][0] = 1;
      if (ch == '>' || ch == '+' || ch == '-' || ch == 'U' || ch == 'L' ||
          ch == 'D')
        a[i][j][1] = 1;
      if (ch == 'v' || ch == '+' || ch == '|' || ch == 'R' || ch == 'L' ||
          ch == 'U')
        a[i][j][2] = 1;
      if (ch == '<' || ch == '+' || ch == '-' || ch == 'R' || ch == 'U' ||
          ch == 'D')
        a[i][j][3] = 1;
    }
  cin >> xt >> yt >> xm >> ym, xt--, yt--, xm--, ym--;
  q.push({xt, yt, 0}), dd[xt][yt][0] = 1;
  while (q.size()) {
    s v = q.front();
    int x = v.x, y = v.y, d = v.d;
    if (!dd[x][y][(d + 1) % 4])
      dd[x][y][(d + 1) % 4] = dd[x][y][d] + 1, q.push({x, y, (d + 1) % 4});
    for (int i = 0; i < 4; i++) {
      int x2 = x + xx[i], y2 = y + yy[i];
      if (x2 >= 0 && x2 < n && y2 >= 0 && y2 < m)
        if (a[x][y][f(i + 2 - d)] && a[x2][y2][f(i - d)])
          if (!dd[x2][y2][d])
            dd[x2][y2][d] = dd[x][y][d] + 1, q.push({x2, y2, d});
    }
    q.pop();
  }
  int mi = 1e9;
  for (int i = 0; i < 4; i++)
    if (dd[xm][ym][i]) mi = min(mi, dd[xm][ym][i]);
  if (mi == 1e9)
    cout << -1;
  else
    cout << mi - 1;
  return 0;
}
