#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
char reqDest[4] = {'v', '^', '>', '<'};
char reqSrc[4] = {'^', 'v', '<', '>'};
string inputMap[1005];
char rot90[1005];
int row, col;
char availDoors[1005][1005];
int dist[4][1005][1005];
string tp;
char input[1005];
pair<int, pair<int, int> > newPos;
void initMaps() {
  rot90['*'] = '*';
  rot90['+'] = '+';
  rot90['|'] = '-';
  rot90['-'] = '|';
  rot90['U'] = 'R';
  rot90['R'] = 'D';
  rot90['D'] = 'L';
  rot90['L'] = 'U';
  rot90['^'] = '>';
  rot90['>'] = 'v';
  rot90['v'] = '<';
  rot90['<'] = '^';
  inputMap['*'] = "";
  inputMap['+'] = "<>v^";
  inputMap['|'] = "^v";
  inputMap['-'] = "<>";
  inputMap['L'] = ">v^";
  inputMap['R'] = "^v<";
  inputMap['U'] = "<>v";
  inputMap['D'] = "^<>";
  inputMap['^'] = "^";
  inputMap['>'] = ">";
  inputMap['v'] = "v";
  inputMap['<'] = "<";
}
bool cango[4][1005][1005];
bool canGo(int sx, int sy, int sr, int d) {
  char st = availDoors[sx][sy];
  char ds = availDoors[sx + dx[d]][sy + dy[d]];
  for (int i = 0; i < sr; i++) {
    st = rot90[st];
    ds = rot90[ds];
  }
  bool canSt = false, canReach = false;
  for (int i = 0; i < inputMap[st].size(); i++) {
    if (reqSrc[d] == inputMap[st][i]) {
      canSt = true;
      break;
    }
  }
  for (int i = 0; i < inputMap[ds].size(); i++) {
    if (reqDest[d] == inputMap[ds][i]) {
      canReach = true;
      break;
    }
  }
  return canReach and canSt;
}
int main() {
  initMaps();
  scanf("%d%d", &row, &col);
  for (int i = 1; i <= row; i++) {
    scanf("%s", input);
    for (int j = 1; j <= col; j++) {
      availDoors[i][j] = input[j - 1];
    }
  }
  memset(dist, -1, sizeof(dist));
  ;
  int startX, startY;
  int destX, destY;
  scanf("%d%d", &startX, &startY);
  scanf("%d%d", &destX, &destY);
  queue<pair<int, pair<int, int> > > Q;
  Q.push(make_pair(0, make_pair(startX, startY)));
  dist[0][startX][startY] = 0;
  while (!Q.empty()) {
    pair<int, pair<int, int> > curr = Q.front();
    Q.pop();
    int currRot = curr.first;
    int currX = curr.second.first;
    int currY = curr.second.second;
    int currD = dist[currRot][currX][currY];
    if (currX == destX and currY == destY) {
      cout << currD << endl;
      return 0;
    }
    int newRot = (currRot + 1) % 4;
    if (dist[newRot][currX][currY] == -1) {
      newPos = make_pair(newRot, make_pair(currX, currY));
      dist[newRot][currX][currY] = currD + 1;
      Q.push(newPos);
    }
    for (int i = 0; i < 4; i++) {
      if (canGo(currX, currY, currRot, i)) {
        int nx = currX + dx[i];
        int ny = currY + dy[i];
        if (nx == destX and ny == destY) {
          cout << currD + 1 << endl;
          return 0;
        }
        if (dist[currRot][nx][ny] == -1) {
          dist[currRot][nx][ny] = currD + 1;
          Q.push(make_pair(currRot, make_pair(nx, ny)));
        }
      }
    }
  }
  cout << "-1" << endl;
  return 0;
}
