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>
struct Vertex {
  int x, y;
  int level;
  bool operator==(const Vertex& other) const {
    return x == other.x && y == other.y && level == other.level;
  }
};
void PrintVertex(const Vertex& v) {
  std::cout << "{" << v.x << "," << v.y << "," << v.level << "}";
}
size_t VertexHash(const Vertex& vertex) {
  return vertex.x * 1000 * 4 + vertex.y * 4 + vertex.level;
}
static const std::unordered_map<char, std::vector<bool>> table = {
    {'+', {true, true, true, true}},    {'-', {false, true, false, true}},
    {'|', {true, false, true, false}},  {'^', {true, false, false, false}},
    {'>', {false, true, false, false}}, {'<', {false, false, false, true}},
    {'v', {false, false, true, false}}, {'L', {true, true, true, false}},
    {'R', {true, false, true, true}},   {'U', {false, true, true, true}},
    {'D', {true, true, false, true}},   {'*', {false, false, false, false}}};
const std::vector<bool>& extract(char x) {
  auto iter = table.find(x);
  return iter->second;
}
void do_smth(int x1, int y1, int direction, int level,
             const std::vector<std::string>& rows,
             std::vector<std::vector<size_t>>* adjacent) {
  int x2 = x1;
  int y2 = y1;
  if (direction == 0) {
    --x2;
  }
  if (direction == 1) {
    ++y2;
  }
  if (direction == 2) {
    ++x2;
  }
  if (direction == 3) {
    --y2;
  }
  if (x2 < 0 || x2 >= rows.size()) {
    return;
  }
  if (y2 < 0 || y2 >= rows[x2].size()) {
    return;
  }
  const auto& first = extract(rows[x1][y1]);
  const auto& second = extract(rows[x2][y2]);
  if (first[(direction + 4 - level) % 4] &&
      second[(direction + 4 - level + 2) % 4]) {
    (*adjacent)[VertexHash(Vertex{x1, y1, level})].push_back(
        VertexHash(Vertex{x2, y2, level}));
  }
}
int BFS(const std::vector<std::vector<size_t>>& adjacent, const Vertex& start,
        int finish_x, int finish_y) {
  std::queue<std::pair<size_t, int>> queue;
  queue.push({VertexHash(start), 0});
  std::vector<bool> visited(1000 * 1000 * 4, false);
  visited[VertexHash(start)] = true;
  auto fin_h = VertexHash(Vertex{finish_x, finish_y, 0});
  while (!queue.empty()) {
    auto p = queue.front();
    queue.pop();
    auto vertex = p.first;
    auto dist = p.second;
    if (vertex - (vertex % 4) == fin_h) {
      return dist;
    }
    for (auto adj : adjacent[vertex]) {
      if (!visited[adj]) {
        queue.push({adj, dist + 1});
        visited[adj] = true;
      }
    }
  }
  return -1;
}
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::string> rows(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> rows[i];
  }
  int start_x, start_y, finish_x, finish_y;
  std::cin >> start_x >> start_y >> finish_x >> finish_y;
  --start_x;
  --start_y;
  --finish_x;
  --finish_y;
  std::vector<std::vector<size_t>> adjacent;
  adjacent.resize(1000 * 1000 * 4 * 2);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int level = 0; level < 4; ++level) {
        adjacent[VertexHash(Vertex{i, j, level})].push_back(
            VertexHash(Vertex{i, j, (level + 1) % 4}));
        do_smth(i, j, 0, level, rows, &adjacent);
        do_smth(i, j, 1, level, rows, &adjacent);
        do_smth(i, j, 2, level, rows, &adjacent);
        do_smth(i, j, 3, level, rows, &adjacent);
      }
    }
  }
  std::cout << BFS(adjacent, {start_x, start_y, 0}, finish_x, finish_y) << "\n";
}