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 long double INF = 1000000000;
const long long INFll = 1ll * INF * INF;
const long double ldINF = 1e+018;
const long double EPS = 0.000000001;
const int sdx[4] = {-1, 0, 1, 0};
const int sdy[4] = {0, 1, 0, -1};
template <typename T>
ostream& operator<<(ostream& out, pair<T, T>& a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T>
istream& operator>>(istream& in, pair<T, T>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (int i = 0; i < a.size(); ++i) in >> a[i];
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> a) {
  for (int i = 0; i < a.size(); ++i)
    if (i == a.size() - 1)
      out << a[i];
    else
      out << a[i] << " ";
}
vector<pair<int, int> > g[1000100];
char v[1100][1100];
vector<int> pre[200];
vector<int> is_door[200][200][5];
inline bool check(int k, vector<int> a, vector<int> b) {
  bool f1 = false, f2 = false;
  if (k == 0) {
    for (int i = 0; i < a.size(); i++)
      if (a[i] == 0) f1 = true;
    for (int j = 0; j < b.size(); j++)
      if (b[j] == 2) f2 = true;
  }
  if (k == 1) {
    for (int i = 0; i < a.size(); i++)
      if (a[i] == 1) f1 = true;
    for (int j = 0; j < b.size(); j++)
      if (b[j] == 3) f2 = true;
  }
  if (k == 2) {
    for (int i = 0; i < a.size(); i++)
      if (a[i] == 2) f1 = true;
    for (int j = 0; j < b.size(); j++)
      if (b[j] == 0) f2 = true;
  }
  if (k == 3) {
    for (int i = 0; i < a.size(); i++)
      if (a[i] == 3) f1 = true;
    for (int j = 0; j < b.size(); j++)
      if (b[j] == 1) f2 = true;
  }
  return f1 && f2;
}
long long dist[5][1001000];
int main() {
  pre['+'] = {0, 1, 2, 3};
  pre['-'] = {1, 3};
  pre['|'] = {0, 2};
  pre['^'] = {0};
  pre['>'] = {1};
  pre['<'] = {3};
  pre['v'] = {2};
  pre['L'] = {0, 1, 2};
  pre['R'] = {0, 2, 3};
  pre['U'] = {1, 2, 3};
  pre['D'] = {0, 1, 3};
  string t = "+-|^><vLRUD";
  for (int i = 0; i < t.size(); i++)
    for (int j = 0; j < t.size(); j++) {
      for (int p = 0; p < 4; p++) {
        vector<int> a = pre[t[i]], b = pre[t[j]];
        for (int l = 0; l < a.size(); l++) a[l] = (a[l] + p) % 4;
        for (int l = 0; l < b.size(); l++) b[l] = (b[l] + p) % 4;
        for (int k = 0; k < 4; k++)
          if (check(k, a, b)) is_door[t[i]][t[j]][k].push_back(p);
      }
    }
  int n, m;
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) scanf("%c", &v[i][j]);
    scanf("\n");
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '*') continue;
      for (int k = 0; k < 4; k++) {
        int x = sdx[k] + i, y = sdy[k] + j;
        if (v[x][y] == '*' || x < 0 || y < 0 || x >= n || y >= m) continue;
        char c = v[i][j], d = v[x][y];
        for (int l = 0; l < is_door[c][d][k].size(); l++) {
          int p = is_door[c][d][k][l];
          int from = i * m + j;
          int to = x * m + y;
          g[from].push_back(make_pair(to, p));
        }
      }
    }
  }
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n * m; j++) dist[i][j] = INFll;
  priority_queue<pair<long long, pair<int, int> > > q;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1--, y1--, x2--, y2--;
  int s = x1 * m + y1;
  int f = x2 * m + y2;
  for (int i = 0; i < 4; i++) dist[i][s] = 0;
  q.push(make_pair(0, make_pair(s, 0)));
  while (!q.empty()) {
    int x = q.top().second.first;
    int cur = q.top().second.second;
    q.pop();
    for (int i = 0; i < g[x].size(); i++) {
      int to = g[x][i].first;
      int p = g[x][i].second;
      int w = 1;
      if (p >= cur)
        w += (p - cur);
      else
        w += (4 - cur + p);
      if (dist[p][to] > dist[cur][x] + w) {
        dist[p][to] = dist[cur][x] + w;
        q.push(make_pair(-dist[p][to], make_pair(to, p)));
      }
    }
  }
  long long mn = INFll;
  for (int i = 0; i < 4; i++) mn = min(mn, dist[i][f]);
  if (mn == INFll)
    cout << -1 << endl;
  else
    cout << mn << endl;
  if (0)
    cerr << fixed << setprecision(0)
         << "TIME = " << clock() / (long double)CLOCKS_PER_SEC * 1000 << "\n";
  return 0;
}