#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};
struct Cell {
  bool door[4];
  Cell() {}
  Cell(bool a, bool b, bool c, bool d) {
    door[0] = a;
    door[1] = b;
    door[2] = c;
    door[3] = d;
  }
  bool hasDoor(int shift, int dir) { return door[(dir + 4 - shift) % 4]; }
};
Cell parse(char ch) {
  if (ch == '+') {
    return Cell(1, 1, 1, 1);
  }
  if (ch == '-') {
    return Cell(1, 0, 1, 0);
  }
  if (ch == '|') {
    return Cell(0, 1, 0, 1);
  }
  if (ch == '^') {
    return Cell(0, 1, 0, 0);
  }
  if (ch == '>') {
    return Cell(0, 0, 1, 0);
  }
  if (ch == '<') {
    return Cell(1, 0, 0, 0);
  }
  if (ch == 'v') {
    return Cell(0, 0, 0, 1);
  }
  if (ch == 'L') {
    return Cell(0, 1, 1, 1);
  }
  if (ch == 'U') {
    return Cell(1, 0, 1, 1);
  }
  if (ch == 'R') {
    return Cell(1, 1, 0, 1);
  }
  if (ch == 'D') {
    return Cell(1, 1, 1, 0);
  }
  if (ch == '*') {
    return Cell(0, 0, 0, 0);
  }
  assert(0);
}
const int N = 1001;
Cell a[N][N];
char s[N][N];
struct Position {
  int x, y, shift;
  Position(int x, int y, int shift) : x(x), y(y), shift(shift % 4) {}
};
int dist[N][N][4];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
    for (int j = 0; j < m; ++j) {
      a[i][j] = parse(s[i][j]);
    }
  }
  int x0, y0;
  scanf("%d%d", &x0, &y0);
  int x1, y1;
  scanf("%d%d", &x1, &y1);
  --x0, --y0, --x1, --y1;
  memset(dist, -1, sizeof(dist));
  vector<Position> q;
  q.push_back(Position(x0, y0, 0));
  dist[x0][y0][0] = 0;
  for (int i = 0; i < int(q.size()); ++i) {
    Position cur = q[i];
    ;
    if (cur.x == x1 && cur.y == y1) {
      printf("%d\n", dist[cur.x][cur.y][cur.shift]);
      return 0;
    }
    Position next = Position(cur.x, cur.y, cur.shift + 1);
    if (dist[next.x][next.y][next.shift] == -1) {
      q.push_back(next);
      dist[next.x][next.y][next.shift] = dist[cur.x][cur.y][cur.shift] + 1;
    }
    for (int j = 0; j < 4; ++j) {
      Position next = Position(cur.x + dx[j], cur.y + dy[j], cur.shift);
      if (!(0 <= next.x && next.x < n && 0 <= next.y && next.y < m)) {
        continue;
      }
      if (dist[next.x][next.y][next.shift] != -1) {
        continue;
      }
      if (a[cur.x][cur.y].hasDoor(cur.shift, j) &&
          a[next.x][next.y].hasDoor(cur.shift, j ^ 2)) {
        q.push_back(next);
        dist[next.x][next.y][next.shift] = dist[cur.x][cur.y][cur.shift] + 1;
      }
    }
  }
  printf("-1\n");
  return 0;
}
