#include <bits/stdc++.h>
using namespace std;
const int MAX = (const int)(1e3 + 11);
static inline char mask(char ch) {
  static char B = 1, R = 2, T = 4, L = 8;
  if (ch == '+') return L | T | R | B;
  if (ch == '-') return L | R;
  if (ch == '|') return T | B;
  if (ch == '^') return T;
  if (ch == '>') return R;
  if (ch == '<') return L;
  if (ch == 'v') return B;
  if (ch == 'L') return T | R | B;
  if (ch == 'R') return L | T | B;
  if (ch == 'U') return L | R | B;
  if (ch == 'D') return L | T | R;
  assert(false);
  return 0;
}
static inline char rotate_once(char ch) {
  if (ch == '+') return ch;
  if (ch == '-') return '|';
  if (ch == '|') return '-';
  if (ch == '^') return '>';
  if (ch == '>') return 'v';
  if (ch == '<') return '^';
  if (ch == 'v') return '<';
  if (ch == 'L') return 'U';
  if (ch == 'R') return 'D';
  if (ch == 'U') return 'R';
  if (ch == 'D') return 'L';
  assert(false);
  return ch;
}
static inline char rotate(char ch, int cnt) {
  char res = ch;
  for (int i = 0; i < cnt; ++i) {
    res = rotate_once(res);
  }
  return res;
}
static inline char where(int cx, int cy, int nx, int ny) {
  assert((cx == nx) || (cy == ny));
  static char B = 1, R = 2, T = 4, L = 8;
  if (cx < nx) return B;
  if (cx > nx) return T;
  if (cy < ny) return R;
  if (cy > ny) return L;
  assert(false);
  return 0;
}
struct Node {
  Node(int x, int y, int r) : x_(x), y_(y), r_(r) {}
  int x_, y_, r_;
};
static const int dx[] = {1, -1, 0, 0};
static const int dy[] = {0, 0, 1, -1};
int N, M;
char A[MAX][MAX];
int L[5][MAX][MAX];
int TX, TY;
int MX, MY;
char C[5][MAX][MAX];
static bool can(int cx, int cy, int nx, int ny, int r) {
  assert(cx >= 0 && cy >= 0 && A[cx][cy] != '*');
  if (nx < 0 || ny < 0 || nx >= N || ny >= M || A[nx][ny] == '*') return false;
  const auto m1 = C[r][cx][cy];
  const auto m2 = C[r][nx][ny];
  const auto w1 = where(cx, cy, nx, ny);
  const auto w2 = where(nx, ny, cx, cy);
  return (w1 & m1) && (w2 & m2);
}
static void solve(std::int32_t test) {
  memset(L, 0x4F, sizeof(L));
  memset(C, 0, sizeof(C));
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  cin >> TX >> TY;
  cin >> MX >> MY;
  TX--;
  TY--;
  MX--;
  MY--;
  for (int r = 0; r < 4; ++r) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < M; ++j) {
        if (A[i][j] != '*') C[r][i][j] = mask(rotate(A[i][j], r));
      }
    }
  }
  L[0][TX][TY] = 0;
  queue<Node> Q;
  Q.push(Node(TX, TY, 0));
  while (!Q.empty()) {
    const auto top = Q.front();
    const auto cx = top.x_, cy = top.y_, cr = top.r_;
    Q.pop();
    {
      const int rr = (cr + 1) % 4;
      if (L[rr][cx][cy] > L[cr][cx][cy] + 1) {
        L[rr][cx][cy] = L[cr][cx][cy] + 1;
        Q.push(Node(cx, cy, rr));
      }
    }
    for (int j = 0; j < 4; ++j) {
      const int nx = cx + dx[j];
      const int ny = cy + dy[j];
      if (can(cx, cy, nx, ny, cr) && L[cr][nx][ny] > L[cr][cx][cy] + 1) {
        L[cr][nx][ny] = L[cr][cx][cy] + 1;
        Q.push(Node(nx, ny, cr));
      }
    }
  }
  int res = L[0][MAX - 1][MAX - 1];
  for (int i = 0; i < 4; ++i) {
    res = min(res, L[i][MX][MY]);
  }
  if (res != L[0][MAX - 1][MAX - 1])
    cout << res;
  else
    cout << -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout << setprecision(12) << fixed;
  solve(0);
  return 0;
}
