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>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = (int)1e9 + 7;
const long long LINF = (long long)1e18 + 7;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 7;
const double EPS = (double)1e-6;
void file() {}
string A[1007];
vector<bool> G[1007][1007];
int n, m;
void dijkstra(int x, int y, int xk, int yk) {
  priority_queue<pair<pair<int, int>, pair<int, int> > > Q;
  vector<vector<vector<int> > > d(
      1007, vector<vector<int> >(1007, vector<int>(4, INF)));
  d[x][y][0] = 0;
  d[x][y][1] = 1;
  d[x][y][2] = 2;
  d[x][y][3] = 3;
  Q.push(make_pair(make_pair(0, 0), make_pair(x, y)));
  Q.push(make_pair(make_pair(-1, 1), make_pair(x, y)));
  Q.push(make_pair(make_pair(-2, 2), make_pair(x, y)));
  Q.push(make_pair(make_pair(-3, 3), make_pair(x, y)));
  vector<bool> ff(4), ffc(4);
  while (!Q.empty()) {
    if (*max_element(d[xk][yk].begin(), d[xk][yk].end()) != INF) {
      printf("%d", *min_element(d[xk][yk].begin(), d[xk][yk].end()));
      exit(0);
    }
    auto V = Q.top();
    Q.pop();
    int kx = V.second.first, ky = V.second.second;
    int time = -V.first.first, kolp = V.first.second;
    for (int i = 0; i < (int)4; ++i) {
      int ko = (kolp + i) % 4;
      for (int j = 0; j < (int)4; ++j) {
        ff[j] = G[kx][ky][(j - ko + 4) % 4];
      }
      if (kx - 1 >= 0) {
        for (int j = 0; j < (int)4; ++j) {
          ffc[j] = G[kx - 1][ky][(j - ko + 4) % 4];
        }
        if (ffc[2] && ff[0]) {
          if (d[kx - 1][ky][ko] > time + 1) {
            d[kx - 1][ky][ko] = time + 1;
            Q.push(make_pair(make_pair(-time - 1, ko), make_pair(kx - 1, ky)));
          }
        }
      }
      if (ky + 1 < m) {
        for (int j = 0; j < (int)4; ++j) {
          ffc[j] = G[kx][ky + 1][(j - ko + 4) % 4];
        }
        if (ffc[3] && ff[1]) {
          if (d[kx][ky + 1][ko] > time + 1) {
            d[kx][ky + 1][ko] = time + 1;
            Q.push(make_pair(make_pair(-time - 1, ko), make_pair(kx, ky + 1)));
          }
        }
      }
      if (kx + 1 < n) {
        for (int j = 0; j < (int)4; ++j) {
          ffc[j] = G[kx + 1][ky][(j - ko + 4) % 4];
        }
        if (ffc[0] && ff[2]) {
          if (d[kx + 1][ky][ko] > time + 1) {
            d[kx + 1][ky][ko] = time + 1;
            Q.push(make_pair(make_pair(-time - 1, ko), make_pair(kx + 1, ky)));
          }
        }
      }
      if (ky - 1 >= 0) {
        for (int j = 0; j < (int)4; ++j) {
          ffc[j] = G[kx][ky - 1][(j - ko + 4) % 4];
        }
        if (ffc[1] && ff[3]) {
          if (d[kx][ky - 1][ko] > time + 1) {
            d[kx][ky - 1][ko] = time + 1;
            Q.push(make_pair(make_pair(-time - 1, ko), make_pair(kx, ky - 1)));
          }
        }
      }
      ++time;
    }
  }
  if (*min_element(d[xk][yk].begin(), d[xk][yk].end()) == INF) {
    puts("-1");
  } else {
    printf("%d", *min_element(d[xk][yk].begin(), d[xk][yk].end()));
  }
}
int main() {
  file();
  scanf("%d%d", &n, &m);
  getline(cin, A[0]);
  for (int i = 0; i < (int)n; ++i) {
    getline(cin, A[i]);
  }
  for (int i = 0; i < (int)n; ++i) {
    for (int j = 0; j < (int)m; ++j) {
      G[i][j].resize(4);
    }
  }
  for (int i = 0; i < (int)n; ++i) {
    for (int j = 0; j < (int)m; ++j) {
      if (A[i][j] == '+' || A[i][j] == '|' || A[i][j] == '^' ||
          ('A' < A[i][j] && A[i][j] < 'Z' && A[i][j] != 'U')) {
        G[i][j][0] = 1;
      } else {
        G[i][j][0] = 0;
      }
      if (A[i][j] == '+' || A[i][j] == '-' || A[i][j] == '>' ||
          ('A' < A[i][j] && A[i][j] < 'Z' && A[i][j] != 'R')) {
        G[i][j][1] = 1;
      } else {
        G[i][j][1] = 0;
      }
      if (A[i][j] == '+' || A[i][j] == '|' || A[i][j] == 'v' ||
          ('A' < A[i][j] && A[i][j] < 'Z' && A[i][j] != 'D')) {
        G[i][j][2] = 1;
      } else {
        G[i][j][2] = 0;
      }
      if (A[i][j] == '+' || A[i][j] == '-' || A[i][j] == '<' ||
          ('A' < A[i][j] && A[i][j] < 'Z' && A[i][j] != 'L')) {
        G[i][j][3] = 1;
      } else {
        G[i][j][3] = 0;
      }
    }
  }
  int xt, yt, xm, ym;
  scanf("%d%d", &xt, &yt);
  scanf("%d%d", &xm, &ym);
  --xt, --yt, --xm, --ym;
  dijkstra(xt, yt, xm, ym);
  return 0;
}