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 clang diagnostic ignored "-Wc++98-compat-pedantic"
#pragma clang diagnostic ignored "-Wunused-macros"
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wsign-compare"
using namespace std;
template <typename T, typename I = typename T::iterator>
void read(T &cnt) {
  for (auto &x : cnt) cin >> x;
}
template <typename S, typename T>
istream &operator>>(istream &in, pair<S, T> &p) {
  return in >> p.first >> p.second;
}
template <typename S, typename T>
ostream &operator<<(ostream &out, const pair<S, T> &p) {
  return out << "{" << p.first << ", " << p.second << "}";
}
template <typename T>
struct show_container {
  const T &container;
  show_container(const T &container_) : container(container_) {}
};
template <typename T>
ostream &operator<<(ostream &o, const show_container<T> &thing) {
  bool first = true;
  o << "{";
  for (const auto &x : thing.container) {
    if (!first) o << ", ";
    first = false;
    o << x;
  }
  o << "}";
  return o;
}
template <typename T>
show_container<T> show(const T &container) {
  return show_container<T>(container);
}
static const bool debug = false;
template <typename T, typename Q, typename S>
bool Bounded(const T &x, const Q &a, const S &b) {
  return a <= x && x <= b;
}
template <typename T>
int sz(const T &x) {
  return x.size();
}
template <typename T, typename Q>
bool mem(const T &s, const Q &x) {
  return s.find(x) != s.end();
}
template <typename T>
void umin(T &x, const T &y) {
  x = min(x, y);
}
template <typename T>
void umax(T &x, const T &y) {
  x = max(x, y);
}
template <typename T>
int sign(const T &x) {
  return x == 0 ? 0 : x > 0 ? 1 : -1;
}
template <typename T>
T square(const T &x) {
  return x * x;
}
struct Pos {
  int r, c, rot;
  Pos(int r = -1, int c = -1, int rot = 0) : r(r), c(c), rot(rot) {}
  bool operator<(Pos p) const { return tie(r, c, rot) < tie(p.r, p.c, p.rot); }
};
bool solve() {
  int N, M;
  cin >> N >> M;
  if (!cin) return false;
  vector<string> S(N);
  read(S);
  pair<int, int> start, end;
  cin >> start >> end;
  --start.first, --start.second, --end.first, --end.second;
  auto okay = [&](Pos p) {
    return Bounded(p.r, 0, N - 1) && Bounded(p.c, 0, M - 1);
  };
  auto rotate = [](int d, int rot) { return (d - rot + 8) % 4; };
  const string doorTypes = "+-|^><vLRUD*";
  const int DR[4] = {0, -1, 0, 1}, DC[4] = {1, 0, -1, 0};
  vector<int> blockDirs[128];
  blockDirs[int('+')] = {0, 1, 2, 3};
  blockDirs[int('-')] = {0, 2};
  blockDirs[int('|')] = {1, 3};
  blockDirs[int('^')] = {1};
  blockDirs[int('>')] = {0};
  blockDirs[int('<')] = {2};
  blockDirs[int('v')] = {3};
  blockDirs[int('L')] = {0, 1, 3};
  blockDirs[int('R')] = {1, 2, 3};
  blockDirs[int('U')] = {0, 2, 3};
  blockDirs[int('D')] = {0, 1, 2};
  blockDirs[int('*')] = {};
  bool oppositeDoor[4][128][4];
  memset(oppositeDoor, 0, sizeof(oppositeDoor));
  for (char from : doorTypes) {
    for (char to : doorTypes) {
      for (int rot = 0; rot < int(4); ++rot) {
        for (int thisDir : blockDirs[int(from)]) {
          oppositeDoor[thisDir][int(to)][rot] = false;
          for (int otherDir : blockDirs[int(to)]) {
            if (rotate(thisDir, rot) == (2 + rotate(otherDir, rot)) % 4) {
              oppositeDoor[thisDir][int(to)][rot] = true;
              break;
            }
          }
        }
      }
    }
  }
  int ans = -1;
  static int dist[1024][1024][4];
  memset(dist, 127, sizeof(dist));
  static bool seen[1024][1024][4];
  memset(seen, 0, sizeof(seen));
  Pos beginPos = {start.first, start.second, 0};
  queue<Pos> q;
  q.push(beginPos);
  dist[beginPos.r][beginPos.c][beginPos.rot] = 0;
  seen[beginPos.r][beginPos.c][beginPos.rot] = true;
  while (!q.empty()) {
    Pos u = q.front();
    q.pop();
    if (u.r == end.first && u.c == end.second) {
      ans = dist[u.r][u.c][u.rot];
      break;
    }
    {
      Pos v = {u.r, u.c, (u.rot + 1) % 4};
      if (!seen[v.r][v.c][v.rot]) {
        seen[v.r][v.c][v.rot] = true;
        dist[v.r][v.c][v.rot] = 1 + dist[u.r][u.c][u.rot];
        q.push(v);
      }
    }
    for (int blockDir : blockDirs[int(S[u.r][u.c])]) {
      int dir = rotate(blockDir, u.rot);
      Pos v = {u.r + DR[dir], u.c + DC[dir], u.rot};
      if (!okay(v)) continue;
      if (!oppositeDoor[blockDir][int(S[v.r][v.c])][u.rot]) continue;
      int delta = 1 + dist[u.r][u.c][u.rot];
      if (!seen[v.r][v.c][v.rot]) {
        seen[v.r][v.c][v.rot] = true;
        dist[v.r][v.c][v.rot] = delta;
        q.push(v);
      }
    }
  }
  cout << ans << endl;
  return true;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}