#include <bits/stdc++.h>
using namespace std;
int const N = 1010;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  bool d[N][N][4];
  bool v[N][N][4];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int k = 0; k < 4; k++) {
        v[i][j][k] = false;
        d[i][j][k] = false;
      }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if ((s[j] == '+') || (s[j] == '|') || (s[j] == '^') || (s[j] == 'L') ||
          (s[j] == 'R') || (s[j] == 'D'))
        d[i][j][0] = true;
      if ((s[j] == '+') || (s[j] == '-') || (s[j] == '<') || (s[j] == 'U') ||
          (s[j] == 'R') || (s[j] == 'D'))
        d[i][j][1] = true;
      if ((s[j] == '+') || (s[j] == '|') || (s[j] == 'v') || (s[j] == 'U') ||
          (s[j] == 'R') || (s[j] == 'L'))
        d[i][j][2] = true;
      if ((s[j] == '+') || (s[j] == '-') || (s[j] == '>') || (s[j] == 'U') ||
          (s[j] == 'L') || (s[j] == 'D'))
        d[i][j][3] = true;
    }
  }
  int tx, ty, mx, my;
  scanf("%d %d", &tx, &ty);
  scanf("%d %d", &mx, &my);
  queue<pair<pair<pair<int, int>, int>, int>> Q;
  Q.push({{{tx - 1, ty - 1}, 0}, 0});
  v[tx - 1][ty - 1][0] = true;
  while (!Q.empty()) {
    auto curr = Q.front();
    int currx = curr.first.first.first;
    int curry = curr.first.first.second;
    int currd = curr.first.second;
    int currt = curr.second;
    if ((currx == mx - 1) && (curry == my - 1)) {
      printf("%d\n", currt);
      return 0;
    }
    if (!v[currx][curry][(currd + 1) % 4]) {
      v[currx][curry][(currd + 1) % 4] = true;
      Q.push({{{currx, curry}, (currd + 1) % 4}, currt + 1});
    }
    if ((currx > 0) && (!v[currx - 1][curry][currd]) &&
        d[currx][curry][(currd + 0) % 4] &&
        d[currx - 1][curry][(currd + 2) % 4]) {
      v[currx - 1][curry][currd] = true;
      Q.push({{{currx - 1, curry}, currd}, currt + 1});
    }
    if ((currx < n) && (!v[currx + 1][curry][currd]) &&
        d[currx][curry][(currd + 2) % 4] &&
        d[currx + 1][curry][(currd + 0) % 4]) {
      v[currx + 1][curry][currd] = true;
      Q.push({{{currx + 1, curry}, currd}, currt + 1});
    }
    if ((curry > 0) && (!v[currx][curry - 1][currd]) &&
        d[currx][curry][(currd + 1) % 4] &&
        d[currx][curry - 1][(currd + 3) % 4]) {
      v[currx][curry - 1][currd] = true;
      Q.push({{{currx, curry - 1}, currd}, currt + 1});
    }
    if ((curry < m) && (!v[currx][curry + 1][currd]) &&
        d[currx][curry][(currd + 3) % 4] &&
        d[currx][curry + 1][(currd + 1) % 4]) {
      v[currx][curry + 1][currd] = true;
      Q.push({{{currx, curry + 1}, currd}, currt + 1});
    }
    Q.pop();
  }
  printf("-1\n");
  return 0;
}
