#include <bits/stdc++.h>
using namespace std;
char s[1005][1005];
int button[1005][1005][4][4];
int vis[1005][1005][4];
struct node {
  int x, y, time, f;
  node(int a, int b, int c, int d) : x(a), y(b), time(c), f(d){};
};
int step[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
int n, m;
void init() {
  memset(button, 0, sizeof(button));
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      switch (s[i][j]) {
        case '+': {
          for (int k = 0; k < 4; k++) button[i][j][0][k] = 1;
        } break;
        case '-': {
          button[i][j][0][1] = 1;
          button[i][j][0][3] = 1;
        } break;
        case '|': {
          button[i][j][0][0] = 1;
          button[i][j][0][2] = 1;
        } break;
        case '^': {
          button[i][j][0][0] = 1;
        } break;
        case '>': {
          button[i][j][0][1] = 1;
        } break;
        case 'v': {
          button[i][j][0][2] = 1;
        } break;
        case '<': {
          button[i][j][0][3] = 1;
        } break;
        case 'U': {
          button[i][j][0][1] = 1;
          button[i][j][0][2] = 1;
          button[i][j][0][3] = 1;
        } break;
        case 'R': {
          button[i][j][0][0] = 1;
          button[i][j][0][2] = 1;
          button[i][j][0][3] = 1;
        } break;
        case 'D': {
          button[i][j][0][0] = 1;
          button[i][j][0][1] = 1;
          button[i][j][0][3] = 1;
        } break;
        case 'L': {
          button[i][j][0][0] = 1;
          button[i][j][0][1] = 1;
          button[i][j][0][2] = 1;
        } break;
      }
      for (int f = 1; f < 4; f++)
        for (int k = 0; k < 4; k++)
          button[i][j][f][(k + 1) % 4] = button[i][j][f - 1][k];
    }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; i++) scanf(" %s", s[i]);
    init();
    int sx, sy, ex, ey, flag = 0;
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    ex--;
    ey--;
    node d(sx - 1, sy - 1, 0, 0);
    queue<node> Q;
    Q.push(d);
    while (!Q.empty()) {
      node a = Q.front();
      Q.pop();
      if (a.x == ex && a.y == ey) {
        printf("%d\n", a.time);
        flag = 1;
        break;
      }
      for (int i = 0; i < 4; i++) {
        node u = a;
        if (button[u.x][u.y][u.f][i] == 1) {
          u.x += step[i][0];
          u.y += step[i][1];
          if (u.x < 0 || u.x >= n || u.y < 0 || u.y >= m) continue;
          if (vis[u.x][u.y][u.f] == 1 ||
              button[u.x][u.y][u.f][(i + 2) % 4] != 1)
            continue;
          vis[u.x][u.y][u.f] = 1;
          u.time += 1;
          Q.push(u);
        }
      }
      a.f = (a.f + 1) % 4;
      a.time += 1;
      if (vis[a.x][a.y][a.f] == 1) continue;
      vis[a.x][a.y][a.f] = 1;
      Q.push(a);
    }
    if (!flag) printf("-1\n");
  }
}
