#include <bits/stdc++.h>
using namespace std;
const int limite = 2000;
int movi[] = {0, -1, 0, 1};
int movj[] = {1, 0, -1, 0};
int t[limite][limite][4];
int visto[limite][limite][4];
int dist[limite][limite][4];
char buff[limite];
struct elem {
  int i, j, r;
  elem() {}
  elem(int i, int j, int r) : i(i), j(j), r(r) {}
};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", buff);
    for (int j = 1; j <= m; j++) {
      char c = buff[j - 1];
      int(&v)[4] = t[i][j];
      if (c == '+') v[0] = v[1] = v[2] = v[3] = 1;
      if (c == '-') v[0] = v[2] = 1;
      if (c == '|') v[1] = v[3] = 1;
      if (c == '>') v[0] = 1;
      if (c == '^') v[1] = 1;
      if (c == '<') v[2] = 1;
      if (c == 'v') v[3] = 1;
      if (c == 'R') v[1] = v[2] = v[3] = 1;
      if (c == 'U') v[0] = v[2] = v[3] = 1;
      if (c == 'L') v[0] = v[1] = v[3] = 1;
      if (c == 'D') v[0] = v[1] = v[2] = 1;
    }
  }
  int iini, jini, ifin, jfin;
  scanf("%d%d%d%d", &iini, &jini, &ifin, &jfin);
  queue<elem> q;
  q.push(elem(iini, jini, 0));
  visto[iini][jini][0] = 1;
  while (not q.empty()) {
    elem e = q.front();
    q.pop();
    int i = e.i;
    int j = e.j;
    int r = e.r;
    if (i == ifin and j == jfin) {
      printf("%d\n", dist[i][j][r]);
      exit(0);
    }
    int de = dist[i][j][r];
    for (int d = 0; d < 4; d++) {
      int nexti = i + movi[d];
      int nextj = j + movj[d];
      if (t[i][j][(r + d) % 4] and t[nexti][nextj][(r + d + 2) % 4] and
          not visto[nexti][nextj][r]) {
        visto[nexti][nextj][r] = 1;
        dist[nexti][nextj][r] = de + 1;
        q.push(elem(nexti, nextj, r));
      }
    }
    int nextr = (r + 1) % 4;
    if (not visto[i][j][nextr]) {
      visto[i][j][nextr] = 1;
      dist[i][j][nextr] = de + 1;
      q.push(elem(i, j, nextr));
    }
  }
  printf("-1\n");
}
