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 inf = 0x3f3f3f3f;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int m[5][1002][1002];
int a[1002][1002];
char str[1005][1005];
bool vis[5][1002][1002];
int f[5][1002][1002];
pair<int, pair<int, int> > q[6000000];
int n, r;
int getsum(char ch) {
  if (ch == '+') return 0;
  if (ch == '-') return 1;
  if (ch == '|') return 2;
  if (ch == '^') return 3;
  if (ch == '>') return 4;
  if (ch == 'v') return 5;
  if (ch == '<') return 6;
  if (ch == 'L') return 7;
  if (ch == 'U') return 8;
  if (ch == 'R') return 9;
  if (ch == 'D') return 10;
  return 11;
}
bool Left(int x) {
  if (x == 0 || x == 1 || x == 6 || (x >= 7 && x <= 10 && x != 7)) return true;
  return false;
}
bool Right(int x) {
  if (x == 0 || x == 1 || x == 4 || (x >= 7 && x <= 10 && x != 9)) return true;
  return false;
}
bool Up(int x) {
  if (x == 0 || x == 2 || x == 3 || (x >= 7 && x <= 10 && x != 8)) return true;
  return false;
}
bool Down(int x) {
  if (x == 0 || x == 2 || x == 5 || (x >= 7 && x <= 10 && x != 10)) return true;
  return false;
}
int trans(int x) {
  if (x == 0) return 0;
  if (x <= 2) return 3 - x;
  if (x <= 5) return x + 1;
  if (x == 6) return 3;
  if (x <= 9) return x + 1;
  if (x == 10) return 7;
  return 11;
}
bool check(int type, int x, int y, int id) {
  if (id == 0) {
    int xx = m[type][x][y], yy = m[type][x][y + 1];
    if (Right(xx) && Left(yy)) return true;
    return false;
  }
  if (id == 1) {
    int xx = m[type][x][y], yy = m[type][x][y - 1];
    if (Left(xx) && Right(yy)) return true;
    return false;
  }
  if (id == 2) {
    int xx = m[type][x][y], yy = m[type][x + 1][y];
    if (Down(xx) && Up(yy)) return true;
    return false;
  }
  if (id == 3) {
    int xx = m[type][x][y], yy = m[type][x - 1][y];
    if (Up(xx) && Down(yy)) return true;
    return false;
  }
}
int main() {
  int sx, sy, tx, ty;
  scanf("%d %d", &n, &r);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= r; j++) a[i][j] = getsum(str[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= r; j++) {
      m[0][i][j] = a[i][j];
      for (int k = 1; k <= 3; k++) m[k][i][j] = trans(m[k - 1][i][j]);
    }
  memset(f, 0x3f, sizeof(f));
  scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
  int h = 0, t = 1;
  q[t] = make_pair(0, make_pair(sx, sy));
  vis[0][sx][sy] = true;
  f[0][sx][sy] = 0;
  while (h < t) {
    pair<int, pair<int, int> > k = q[++h];
    int type = k.first, x = k.second.first, y = k.second.second;
    if (type == 3 && x == 1 && y == 1) {
      type++;
      type--;
    }
    for (int i = 0; i < 4; i++) {
      int xx = x + d[i][0], yy = y + d[i][1];
      if (xx < 1 || yy < 1 || xx > n || yy > r) continue;
      if (vis[type][xx][yy]) continue;
      if (check(type, x, y, i) == false) continue;
      vis[type][xx][yy] = true;
      q[++t] = make_pair(type, make_pair(xx, yy));
      f[type][xx][yy] = f[type][x][y] + 1;
    }
    int ntype = (type + 1) % 4;
    if (vis[ntype][x][y]) continue;
    vis[ntype][x][y] = true;
    q[++t] = make_pair(ntype, make_pair(x, y));
    f[ntype][x][y] = f[type][x][y] + 1;
  }
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < 4; i++) ans = min(ans, f[i][tx][ty]);
  if (ans == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}