#include <bits/stdc++.h>
using namespace std;
struct triple {
  int fir, sec, thir;
};
const int MN = 1e3 + 5;
const int INF = 1e9 + 5;
map<char, int> mp;
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, 1, 0, -1};
int r1, c1, r2, c2;
int n, m;
int arr[MN][MN];
int res[4][MN][MN];
bool mk[4][MN][MN];
int Rotate(int a) {
  int t = a & 1;
  a /= 2;
  a += (t << 3);
  return a;
}
bool func(int a, int b, int shf) {
  if (shf == 0) {
    return ((a & 8) && (b & 2));
  } else if (shf == 1) {
    return ((a & 4) && (b & 1));
  } else if (shf == 2) {
    return ((a & 2) && (b & 8));
  } else {
    return ((a & 1) && (b & 4));
  }
}
bool isValid(int num, int rot, int a1, int b1, int a2, int b2) {
  if (a1 < 0 || a1 > n - 1 || b1 < 0 || b1 > m - 1) return false;
  if (a2 < 0 || a2 > n - 1 || b2 < 0 || b2 > m - 1) return false;
  int t1 = arr[a1][b1], t2 = arr[a2][b2];
  for (int i = 0; i < rot; ++i) t1 = Rotate(t1), t2 = Rotate(t2);
  return func(t1, t2, num);
}
void prep() {
  mp['*'] = 0, mp['<'] = 1, mp['v'] = 2, mp['>'] = 4;
  mp['-'] = 5, mp['U'] = 7, mp['^'] = 8, mp['|'] = 10;
  mp['R'] = 11, mp['D'] = 13, mp['L'] = 14, mp['+'] = 15;
}
void input() {
  ios_base ::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  char c;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> c;
      arr[i][j] = mp[c];
    }
  for (int l = 0; l < 4; ++l)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) res[l][i][j] = INF;
  cin >> r1 >> c1;
  cin >> r2 >> c2;
  --r1, --c1, --r2, --c2;
  res[0][r1][c1] = 0;
}
void bfs(int a, int b) {
  queue<triple> Q;
  triple t;
  t.fir = 0, t.sec = a, t.thir = b;
  mk[0][a][b] = true;
  Q.push(t);
  triple v, u;
  while (!Q.empty()) {
    v = Q.front();
    for (int i = 0; i < 4; ++i) {
      if (isValid(i, v.fir, v.sec, v.thir, v.sec + x[i], v.thir + y[i]) &&
          !mk[v.fir][v.sec + x[i]][v.thir + y[i]]) {
        u.fir = v.fir, u.sec = v.sec + x[i], u.thir = v.thir + y[i];
        mk[u.fir][u.sec][u.thir] = true;
        res[u.fir][u.sec][u.thir] = res[v.fir][v.sec][v.thir] + 1;
        Q.push(u);
      }
    }
    if (!mk[(v.fir + 1) % 4][v.sec][v.thir]) {
      mk[(v.fir + 1) % 4][v.sec][v.thir] = true;
      res[(v.fir + 1) % 4][v.sec][v.thir] = res[v.fir][v.sec][v.thir] + 1;
      u = v;
      u.fir = (v.fir + 1) % 4;
      Q.push(u);
    }
    Q.pop();
  }
}
int main() {
  prep();
  input();
  bfs(r1, c1);
  int mn = INF;
  for (int i = 0; i < 4; ++i) mn = min(mn, res[i][r2][c2]);
  if (mn == INF)
    cout << -1 << endl;
  else
    cout << mn << endl;
  return 0;
}
