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;
struct gt {
  int x, y, z;
  gt(int _x = 0, int _y = 0, int _z = 0) {
    x = _x;
    y = _y;
    z = _z;
  }
} qu[4000005];
const int mov[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
char s[300][5], a[1005][1005];
int n, m, F[1005][1005][4], dir[300][4];
pair<int, int> T, M;
bool outside(int x, int y) { return x < 1 || x > n || y < 1 || y > m; }
void init() {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      for (int k = 0; k < 4; ++k) F[i][j][k] = 1000000000;
  F[T.first][T.second][0] = 0;
  for (int i = 0; i < 4; ++i) {
    s['+'][i] = '+';
    s['*'][i] = '*';
  }
  s['-'][0] = s['-'][2] = s['|'][1] = s['|'][3] = '-';
  s['-'][1] = s['-'][3] = s['|'][0] = s['|'][2] = '|';
  s['^'][0] = s['>'][3] = s['v'][2] = s['<'][1] = '^';
  s['^'][1] = s['>'][0] = s['v'][3] = s['<'][2] = '>';
  s['^'][2] = s['>'][1] = s['v'][0] = s['<'][3] = 'v';
  s['^'][3] = s['>'][2] = s['v'][1] = s['<'][0] = '<';
  s['L'][0] = s['U'][3] = s['R'][2] = s['D'][1] = 'L';
  s['L'][1] = s['U'][0] = s['R'][3] = s['D'][2] = 'U';
  s['L'][2] = s['U'][1] = s['R'][0] = s['D'][3] = 'R';
  s['L'][3] = s['U'][2] = s['R'][1] = s['D'][0] = 'D';
  for (int i = 0; i < 4; ++i) dir['+'][i] = 1;
  dir['-'][1] = dir['-'][3] = dir['|'][0] = dir['|'][2] = 1;
  dir['^'][0] = dir['>'][1] = dir['v'][2] = dir['<'][3] = 1;
  dir['L'][0] = dir['L'][1] = dir['L'][2] = 1;
  dir['U'][1] = dir['U'][2] = dir['U'][3] = 1;
  dir['R'][0] = dir['R'][2] = dir['R'][3] = 1;
  dir['D'][0] = dir['D'][1] = dir['D'][3] = 1;
}
int opo(int u) {
  if (u == 0) return 2;
  if (u == 1) return 3;
  if (u == 2) return 0;
  return 1;
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s\n", a[i] + 1);
  scanf("%d%d%d%d", &T.first, &T.second, &M.first, &M.second);
  init();
  qu[1].x = T.first;
  qu[1].y = T.second;
  qu[1].z = 0;
  int re = 1;
  for (int i = 1; i <= re; ++i) {
    gt u = qu[i];
    char x = s[a[u.x][u.y]][u.z];
    for (int i = 0; i < 4; ++i) {
      if (dir[x][i] == 0) continue;
      gt nxt(u.x + mov[i][0], u.y + mov[i][1], u.z);
      if (outside(nxt.x, nxt.y) || F[nxt.x][nxt.y][nxt.z] != 1000000000)
        continue;
      char y = s[a[nxt.x][nxt.y]][u.z];
      int j = opo(i);
      if (dir[y][j] == 0) continue;
      F[nxt.x][nxt.y][nxt.z] = F[u.x][u.y][u.z] + 1;
      qu[++re] = nxt;
    }
    if (F[u.x][u.y][(u.z + 1) % 4] != 1000000000) continue;
    F[u.x][u.y][(u.z + 1) % 4] = F[u.x][u.y][u.z] + 1;
    qu[++re] = gt(u.x, u.y, (u.z + 1) % 4);
  }
  int res = 1000000000;
  for (int i = 0; i < 4; ++i) res = min(res, F[M.first][M.second][i]);
  if (res != 1000000000)
    cout << res << endl;
  else
    cout << -1 << endl;
  return 0;
}