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 GCC optimize("Ofast")
using namespace std;
const int MAXN = 1000;
const int MAXD = 4;
const pair<int, int> U = make_pair(-1, 0);
const pair<int, int> D = make_pair(1, 0);
const pair<int, int> L = make_pair(0, -1);
const pair<int, int> R = make_pair(0, 1);
const int up = 0;
const int dn = 1;
const int lf = 2;
const int rg = 3;
struct State {
  int r, c, dir;
  State(int r, int c, int dir) : r(r), c(c), dir(dir){};
};
char g[MAXN][MAXN];
int dist[MAXN][MAXN][MAXD];
map<char, vector<pair<int, pair<int, int> > >[MAXD]> dir;
int n, m;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
}
void preprocess() {
  dir['|'][0].push_back(make_pair(up, U)),
      dir['|'][0].push_back(make_pair(dn, D));
  dir['|'][1].push_back(make_pair(lf, L)),
      dir['|'][1].push_back(make_pair(rg, R));
  dir['|'][2].push_back(make_pair(up, U)),
      dir['|'][2].push_back(make_pair(dn, D));
  dir['|'][3].push_back(make_pair(lf, L)),
      dir['|'][3].push_back(make_pair(rg, R));
  dir['-'][0].push_back(make_pair(lf, L)),
      dir['-'][0].push_back(make_pair(rg, R));
  dir['-'][1].push_back(make_pair(up, U)),
      dir['-'][1].push_back(make_pair(dn, D));
  dir['-'][2].push_back(make_pair(lf, L)),
      dir['-'][2].push_back(make_pair(rg, R));
  dir['-'][3].push_back(make_pair(up, U)),
      dir['-'][3].push_back(make_pair(dn, D));
  dir['^'][0].push_back(make_pair(up, U));
  dir['^'][1].push_back(make_pair(rg, R));
  dir['^'][2].push_back(make_pair(dn, D));
  dir['^'][3].push_back(make_pair(lf, L));
  dir['>'][0].push_back(make_pair(rg, R));
  dir['>'][1].push_back(make_pair(dn, D));
  dir['>'][2].push_back(make_pair(lf, L));
  dir['>'][3].push_back(make_pair(up, U));
  dir['<'][0].push_back(make_pair(lf, L));
  dir['<'][1].push_back(make_pair(up, U));
  dir['<'][2].push_back(make_pair(rg, R));
  dir['<'][3].push_back(make_pair(dn, D));
  dir['v'][0].push_back(make_pair(dn, D));
  dir['v'][1].push_back(make_pair(lf, L));
  dir['v'][2].push_back(make_pair(up, U));
  dir['v'][3].push_back(make_pair(rg, R));
  dir['L'][0].push_back(make_pair(dn, D)),
      dir['L'][0].push_back(make_pair(up, U)),
      dir['L'][0].push_back(make_pair(rg, R));
  dir['L'][1].push_back(make_pair(lf, L)),
      dir['L'][1].push_back(make_pair(rg, R)),
      dir['L'][1].push_back(make_pair(dn, D));
  dir['L'][2].push_back(make_pair(dn, D)),
      dir['L'][2].push_back(make_pair(lf, L)),
      dir['L'][2].push_back(make_pair(up, U));
  dir['L'][3].push_back(make_pair(lf, L)),
      dir['L'][3].push_back(make_pair(up, U)),
      dir['L'][3].push_back(make_pair(rg, R));
  dir['R'][0].push_back(make_pair(dn, D)),
      dir['R'][0].push_back(make_pair(lf, L)),
      dir['R'][0].push_back(make_pair(up, U));
  dir['R'][1].push_back(make_pair(lf, L)),
      dir['R'][1].push_back(make_pair(up, U)),
      dir['R'][1].push_back(make_pair(rg, R));
  dir['R'][2].push_back(make_pair(up, U)),
      dir['R'][2].push_back(make_pair(rg, R)),
      dir['R'][2].push_back(make_pair(dn, D));
  dir['R'][3].push_back(make_pair(dn, D)),
      dir['R'][3].push_back(make_pair(lf, L)),
      dir['R'][3].push_back(make_pair(rg, R));
  dir['U'][0].push_back(make_pair(dn, D)),
      dir['U'][0].push_back(make_pair(lf, L)),
      dir['U'][0].push_back(make_pair(rg, R));
  dir['U'][1].push_back(make_pair(dn, D)),
      dir['U'][1].push_back(make_pair(lf, L)),
      dir['U'][1].push_back(make_pair(up, U));
  dir['U'][2].push_back(make_pair(lf, L)),
      dir['U'][2].push_back(make_pair(up, U)),
      dir['U'][2].push_back(make_pair(rg, R));
  dir['U'][3].push_back(make_pair(dn, D)),
      dir['U'][3].push_back(make_pair(up, U)),
      dir['U'][3].push_back(make_pair(rg, R));
  dir['D'][0].push_back(make_pair(lf, L)),
      dir['D'][0].push_back(make_pair(up, U)),
      dir['D'][0].push_back(make_pair(rg, R));
  dir['D'][1].push_back(make_pair(dn, D)),
      dir['D'][1].push_back(make_pair(up, U)),
      dir['D'][1].push_back(make_pair(rg, R));
  dir['D'][2].push_back(make_pair(dn, D)),
      dir['D'][2].push_back(make_pair(lf, L)),
      dir['D'][2].push_back(make_pair(rg, R));
  dir['D'][3].push_back(make_pair(dn, D)),
      dir['D'][3].push_back(make_pair(lf, L)),
      dir['D'][3].push_back(make_pair(up, U));
  dir['+'][0].push_back(make_pair(lf, L)),
      dir['+'][0].push_back(make_pair(up, U)),
      dir['+'][0].push_back(make_pair(rg, R)),
      dir['+'][0].push_back(make_pair(dn, D));
  dir['+'][1].push_back(make_pair(lf, L)),
      dir['+'][1].push_back(make_pair(up, U)),
      dir['+'][1].push_back(make_pair(rg, R)),
      dir['+'][1].push_back(make_pair(dn, D));
  dir['+'][2].push_back(make_pair(lf, L)),
      dir['+'][2].push_back(make_pair(up, U)),
      dir['+'][2].push_back(make_pair(rg, R)),
      dir['+'][2].push_back(make_pair(dn, D));
  dir['+'][3].push_back(make_pair(lf, L)),
      dir['+'][3].push_back(make_pair(up, U)),
      dir['+'][3].push_back(make_pair(rg, R)),
      dir['+'][3].push_back(make_pair(dn, D));
}
bool ok(int nr, int nc) {
  bool can_r = nr >= 0 and nr < n;
  bool can_c = nc >= 0 and nc < m;
  return can_r and can_c and (g[nr][nc] != '*');
}
bool opposite(pair<int, pair<int, int> > o, char c, int i) {
  int op = -1;
  if (o.first == 0)
    op = 1;
  else if (o.first == 1)
    op = 0;
  else if (o.first == 2)
    op = 3;
  else if (o.first == 3)
    op = 2;
  for (auto v : dir[c][i]) {
    if (v.first == op) return true;
  }
  return false;
}
int solve(int rs, int cs, int rt, int ct) {
  memset(dist, -1, sizeof(dist));
  queue<State> q;
  q.push(State(rs, cs, 0));
  dist[rs][cs][0] = 0;
  while (!q.empty()) {
    State u = q.front();
    q.pop();
    if (u.r == rt and u.c == ct) return dist[u.r][u.c][u.dir];
    char at = g[u.r][u.c];
    for (auto v : dir[at][u.dir]) {
      int nr = u.r + v.second.first, nc = u.c + v.second.second;
      if (ok(nr, nc) and opposite(v, g[nr][nc], u.dir) and
          dist[nr][nc][u.dir] == -1) {
        dist[nr][nc][u.dir] = 1 + dist[u.r][u.c][u.dir];
        q.push(State(nr, nc, u.dir));
      }
    }
    if (dist[u.r][u.c][(u.dir + 1) % MAXD] == -1) {
      dist[u.r][u.c][(u.dir + 1) % MAXD] = 1 + dist[u.r][u.c][u.dir];
      q.push(State(u.r, u.c, (u.dir + 1) % MAXD));
    }
  }
  return -1;
}
int main() {
  fast_io();
  preprocess();
  int rs, cs, rt, ct;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
    }
  }
  cin >> rs >> cs;
  cin >> rt >> ct;
  --rs, --cs;
  --rt, --ct;
  cout << solve(rs, cs, rt, ct) << '\n';
  return 0;
}