#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int MX = 4;
const int INF = 1e9 + 9;
const int N = 1005;
vector<vector<vector<int>>> dis(N, vector<vector<int>>(N, vector<int>(4, INF)));
vector<vector<int>> v(N, vector<int>(N));
vector<int> mask = {1 << 0, 1 << 1, 1 << 2, 1 << 3};
int n, m;
int s1, e1, s2, e2;
int get(char a) {
  if (a == '+') return (mask[0] | mask[1] | mask[2] | mask[3]);
  if (a == '-') return (mask[1] | mask[3]);
  if (a == '|') return (mask[0] | mask[2]);
  if (a == '^') return mask[0];
  if (a == '>') return mask[3];
  if (a == '<') return mask[1];
  if (a == 'v') return mask[2];
  if (a == 'L') return (mask[0] | mask[2] | mask[3]);
  if (a == 'R') return (mask[0] | mask[1] | mask[2]);
  if (a == 'U') return (mask[1] | mask[2] | mask[3]);
  if (a == 'D') return (mask[0] | mask[1] | mask[3]);
  return 0;
}
bool safe(int i, int j) { return ((i > 0) && (j > 0) && (i <= n) && (j <= m)); }
bool go(int i, int j, int x, int y, int state, int dir) {
  bitset<MX> t1, t2;
  for (int k = 0; k < MX; k++) {
    t1[k] = ((v[i][j] >> ((k + state) % MX)) & 1);
    t2[k] = ((v[x][y] >> ((k + state) % MX)) & 1);
  }
  if (dir == 0) {
    if (t1[1] == 1 && t2[3] == 1)
      return true;
    else
      return false;
  } else if (dir == 1) {
    if (t1[3] == 1 && t2[1] == 1)
      return true;
    else
      return false;
  } else if (dir == 2) {
    if (t1[0] == 1 && t2[2] == 1)
      return true;
    else
      return false;
  } else if (dir == 3) {
    if (t1[2] == 1 && t2[0] == 1)
      return true;
    else
      return false;
  }
}
void solve() {
  queue<pair<pair<int, int>, int>> q;
  dis[s1][e1][0] = 0;
  q.push(make_pair(make_pair(s1, e1), 0));
  while (!q.empty()) {
    auto t = q.front();
    q.pop();
    int i = t.first.first, j = t.first.second, state = t.second;
    int d = dis[t.first.first][t.first.second][t.second];
    if (dis[t.first.first][t.first.second][(t.second + 1) % MX] > d + 1) {
      dis[t.first.first][t.first.second][(t.second + 1) % MX] = d + 1;
      q.push(make_pair(t.first, (t.second + 1) % 4));
    }
    if (safe(i, j - 1) && go(i, j, i, j - 1, state, 0) &&
        dis[i][j - 1][state] > d + 1) {
      dis[i][j - 1][state] = d + 1;
      q.push(make_pair(make_pair(i, j - 1), state));
    }
    if (safe(i, j + 1) && go(i, j, i, j + 1, state, 1) &&
        dis[i][j + 1][state] > d + 1) {
      dis[i][j + 1][state] = d + 1;
      q.push(make_pair(make_pair(i, j + 1), state));
    }
    if (safe(i - 1, j) && go(i, j, i - 1, j, state, 2) &&
        dis[i - 1][j][state] > d + 1) {
      dis[i - 1][j][state] = d + 1;
      q.push(make_pair(make_pair(i - 1, j), state));
    }
    if (safe(i + 1, j) && go(i, j, i + 1, j, state, 3) &&
        dis[i + 1][j][state] > d + 1) {
      dis[i + 1][j][state] = d + 1;
      q.push(make_pair(make_pair(i + 1, j), state));
    }
  }
  int ans = INF;
  for (int i = 0; i < MX; i++) ans = min(ans, dis[s2][e2][i]);
  if (ans >= INF)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
}
int main() {
  fast();
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char temp;
      cin >> temp;
      v[i][j] = get(temp);
    }
  cin >> s1 >> e1;
  cin >> s2 >> e2;
  solve();
}
