Problem: Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size n × m and consists of blocks of size 1 × 1.

Each block of the labyrinth has a button that rotates all blocks 90 degrees clockwise. Each block rotates around its center and doesn't change its position in the labyrinth. Also, each block has some number of doors (possibly none). In one minute, Theseus can either push the button in order to rotate all the blocks 90 degrees clockwise or pass to the neighbouring block. Theseus can go from block A to some neighbouring block B only if block A has a door that leads to block B and block B has a door that leads to block A.

Theseus found an entrance to labyrinth and is now located in block (xT, yT) — the block in the row xT and column yT. Theseus know that the Minotaur is hiding in block (xM, yM) and wants to know the minimum number of minutes required to get there.

Theseus is a hero, not a programmer, so he asks you to help him.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in labyrinth, respectively.

Each of the following n lines contains m characters, describing the blocks of the labyrinth. The possible characters are:

  * «+» means this block has 4 doors (one door to each neighbouring block); 
  * «-» means this block has 2 doors — to the left and to the right neighbours; 
  * «|» means this block has 2 doors — to the top and to the bottom neighbours; 
  * «^» means this block has 1 door — to the top neighbour; 
  * «>» means this block has 1 door — to the right neighbour; 
  * «<» means this block has 1 door — to the left neighbour; 
  * «v» means this block has 1 door — to the bottom neighbour;
  * «L» means this block has 3 doors — to all neighbours except left one; 
  * «R» means this block has 3 doors — to all neighbours except right one; 
  * «U» means this block has 3 doors — to all neighbours except top one; 
  * «D» means this block has 3 doors — to all neighbours except bottom one;
  * «*» means this block is a wall and has no doors. 



Left, right, top and bottom are defined from representing labyrinth as a table, where rows are numbered from 1 to n from top to bottom and columns are numbered from 1 to m from left to right.

Next line contains two integers — coordinates of the block (xT, yT) (1 ≤ xT ≤ n, 1 ≤ yT ≤ m), where Theseus is initially located.

Last line contains two integers — coordinates of the block (xM, yM) (1 ≤ xM ≤ n, 1 ≤ yM ≤ m), where Minotaur hides.

It's guaranteed that both the block where Theseus starts and the block where Minotaur is hiding have at least one door. Theseus and Minotaur may be initially located at the same block.

Output

If Theseus is not able to get to Minotaur, then print -1 in the only line of the output. Otherwise, print the minimum number of minutes required to get to the block where Minotaur is hiding.

Examples

Input

2 2
+*
*U
1 1
2 2


Output

-1

Input

2 3
&lt;&gt;&lt;
&gt;&lt;&gt;
1 1
2 1


Output

4

Note

Assume that Theseus starts at the block (xT, yT) at the moment 0.

Solution (in CPP):

Solution:
#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;
}