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 JAVA):

Solution:
/*-
 * Codeforces problem :
 * http://codeforces.com/problemset/problem/676/D
 *
 * 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.
 */

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author Karthik Venkataraman
 * @email kafy83@gmail.com
 */
public class TheseusLabyrinth {

    private static final String TOP = "+|^LRD";
    private static final String BOTTOM = "+|vLRU";
    private static final String LEFT = "+-<RUD";
    private static final String RIGHT = "+->LUD";

    private int n;
    private int m;
    private char[][][] vertexType;
    private boolean[][][] marked;

    class Coord {

        private int x;
        private int y;
        private int orientation;
        private int distance;

        Coord(int x, int y, int orientation, int distance) {
            this.x = x;
            this.y = y;
            this.orientation = orientation;
            this.distance = distance;
        }

        @Override
        public int hashCode() {
            int hash = 3;
            hash = 11 * hash + this.x;
            hash = 11 * hash + this.y;
            hash = 11 * hash + this.orientation;
            hash = 11 * hash + this.distance;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Coord other = (Coord) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            if (this.orientation != other.orientation) {
                return false;
            }
            if (this.distance != other.distance) {
                return false;
            }
            return true;
        }
    }

    private void compute() {
        InputReader sc = new InputReader(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        vertexType = new char[n][m][4];
        marked = new boolean[n][m][4];

        for (int i = 0; i < n; i++) {
            char[] chars = sc.readNext().toCharArray();
            for (int j = 0; j < m; j++) {
                vertexType[i][j][0] = chars[j];
                for (int k = 1; k < 4; k++) {
                    switch (vertexType[i][j][k - 1]) {
                        case '+':
                            vertexType[i][j][k] = '+';
                            break;
                        case '-':
                            vertexType[i][j][k] = '|';
                            break;
                        case '|':
                            vertexType[i][j][k] = '-';
                            break;
                        case '^':
                            vertexType[i][j][k] = '>';
                            break;
                        case '>':
                            vertexType[i][j][k] = 'v';
                            break;
                        case '<':
                            vertexType[i][j][k] = '^';
                            break;
                        case 'v':
                            vertexType[i][j][k] = '<';
                            break;
                        case 'L':
                            vertexType[i][j][k] = 'U';
                            break;
                        case 'R':
                            vertexType[i][j][k] = 'D';
                            break;
                        case 'U':
                            vertexType[i][j][k] = 'R';
                            break;
                        case 'D':
                            vertexType[i][j][k] = 'L';
                            break;
                        case '*':
                            vertexType[i][j][k] = '*';
                            break;
                        default:
                            throw new IllegalArgumentException("invalid input");
                    }
                }
            }
        }

        Graph g = new Graph(new Coord(sc.nextInt() - 1, sc.nextInt() - 1, 0, 0),
                new Coord(sc.nextInt() - 1, sc.nextInt() - 1, 0, 0));
        g.simulate();
    }

    class Graph {

        private Coord source;
        private Coord dest;

        Graph(Coord source, Coord dest) {
            if (source == dest) {
                System.out.println(0);
                System.exit(0);
            }
            this.source = source;
            this.dest = dest;
        }

        private void simulate() {
            SimpleQueue<Coord> q = new SimpleQueue<>();
            q.add(source);
            while (!q.isEmpty()) {
                Coord v = q.remove();

                if (marked[v.x][v.y][v.orientation]) {
                    continue;
                }

                marked[v.x][v.y][v.orientation] = true;

                if (v.x == dest.x && v.y == dest.y) {
                    System.out.println(v.distance);
                    System.exit(0);
                }

                if (!marked[v.x][v.y][(v.orientation + 1) % 4]) {
                    q.add(new Coord(v.x, v.y, (v.orientation + 1) % 4, v.distance + 1));
                }

                if (v.x - 1 >= 0 && !marked[v.x - 1][v.y][v.orientation]
                        && TOP.indexOf(vertexType[v.x][v.y][v.orientation]) != -1
                        && BOTTOM.indexOf(vertexType[v.x - 1][v.y][v.orientation]) != -1) {
                    q.add(new Coord(v.x - 1, v.y, v.orientation, v.distance + 1));
                }

                if (v.x + 1 < n && !marked[v.x + 1][v.y][v.orientation]
                        && BOTTOM.indexOf(vertexType[v.x][v.y][v.orientation]) != -1
                        && TOP.indexOf(vertexType[v.x + 1][v.y][v.orientation]) != -1) {
                    q.add(new Coord(v.x + 1, v.y, v.orientation, v.distance + 1));
                }

                if (v.y - 1 >= 0 && !marked[v.x][v.y - 1][v.orientation]
                        && LEFT.indexOf(vertexType[v.x][v.y][v.orientation]) != -1
                        && RIGHT.indexOf(vertexType[v.x][v.y - 1][v.orientation]) != -1) {
                    q.add(new Coord(v.x, v.y - 1, v.orientation, v.distance + 1));
                }

                if (v.y + 1 < m && !marked[v.x][v.y + 1][v.orientation]
                        && RIGHT.indexOf(vertexType[v.x][v.y][v.orientation]) != -1
                        && LEFT.indexOf(vertexType[v.x][v.y + 1][v.orientation]) != -1) {
                    q.add(new Coord(v.x, v.y + 1, v.orientation, v.distance + 1));
                }
            }
            System.out.println(-1);
            System.exit(0);
        }
    }

    class SimpleQueue<Key> {

        private Key[] q;
        private int size;
        private int first;
        private int last;

        SimpleQueue() {
            q = (Key[]) new Object[n * m * 4];
            size = first = last = 0;
        }

        private boolean isEmpty() {
            return size == 0;
        }

        private void add(Key key) {
            q[last++] = key;
            size++;
            if (last == q.length) {
                last = 0;
            }
        }

        private Key remove() {
            Key key = q[first];
            q[first++] = null;
            size--;
            if (first == q.length) {
                first = 0;
            }
            return key;
        }
    }

    class InputReader {

        private static final int INPUT_KB = 1024;
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), INPUT_KB);
        }

        private String readNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    throw new IllegalArgumentException(ex);
                }
            }
            return tokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(readNext());
        }
    }

    public static void main(String... args) {
        TheseusLabyrinth tl = new TheseusLabyrinth();
        tl.compute();
    }
}