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:
// package codeforces.cf3xx.cf354.div2;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 * Created by hama_du on 2016/07/17.
 */
public class D {
    private static final int INF = (int)1e8;

    private static final int[] DY = {0, 1, 0, -1};
    private static final int[] DX = {1, 0, -1, 0};


    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        char[][] rot = new char[255][];

        rot['+'] = "++++".toCharArray();
        rot['*'] = "****".toCharArray();

        rot['-'] = "-|-|".toCharArray();
        rot['|'] = "|-|-".toCharArray();

        rot['^'] = "^>v<".toCharArray();
        rot['>'] = ">v<^".toCharArray();
        rot['v'] = "v<^>".toCharArray();
        rot['<'] = "<^>v".toCharArray();

        rot['L'] = "LURD".toCharArray();
        rot['U'] = "URDL".toCharArray();
        rot['R'] = "RDLU".toCharArray();
        rot['D'] = "DLUR".toCharArray();

        int[] pass = new int[255];
        pass['+'] = 15;
        pass['-'] = 5;
        pass['|'] = 10;
        pass['^'] = 8;
        pass['>'] = 1;
        pass['v'] = 2;
        pass['<'] = 4;
        pass['L'] = 15^pass['<'];
        pass['U'] = 15^pass['^'];
        pass['R'] = 15^pass['>'];
        pass['D'] = 15^pass['v'];

        int n = in.nextInt();
        int m = in.nextInt();
        char[][] map = new char[n][];
        for (int i = 0; i < n ; i++) {
            map[i] = in.nextToken().toCharArray();
        }
        int[][][] dp = new int[4][n][m];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < n ; j++) {
                Arrays.fill(dp[i][j], INF);
            }
        }
        int sy = in.nextInt()-1;
        int sx = in.nextInt()-1;
        int gy = in.nextInt()-1;
        int gx = in.nextInt()-1;


        int[] que = new int[16000000];
        int qh = 0;
        int qt = 0;
        que[qh++] = sy;
        que[qh++] = sx;
        que[qh++] = 0;
        dp[0][sy][sx] = 0;
        while (qt < qh) {
            int ny = que[qt++];
            int nx = que[qt++];
            int nr = que[qt++];
            int time = dp[nr][ny][nx];

            // rotate
            int tr = (nr+1)%4;
            if (dp[tr][ny][nx] > time+1) {
                dp[tr][ny][nx] = time+1;
                que[qh++] = ny;
                que[qh++] = nx;
                que[qh++] = tr;
            }

            // move
            for (int d = 0 ; d < 4 ; d++) {
                int ty = ny+DY[d];
                int tx = nx+DX[d];
                if (ty < 0 || tx < 0 || ty >= n || tx >= m) {
                    continue;
                }
                char fromChar = rot[map[ny][nx]][nr];
                char toChar = rot[map[ty][tx]][nr];

                int backD = (d+2)%4;
                if ((pass[fromChar] & (1<<d)) >= 1 && (pass[toChar] & (1<<backD)) >= 1) {
                    if (dp[nr][ty][tx] > time+1) {
                        dp[nr][ty][tx] = time+1;
                        que[qh++] = ty;
                        que[qh++] = tx;
                        que[qh++] = nr;
                    }
                }
            }
        }

        int min = INF;
        for (int i = 0; i < 4 ; i++) {
            min = Math.min(min, dp[i][gy][gx]);
        }
        out.println(min >= INF ? -1 : min);
        out.flush();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            if ('a' <= c && c <= 'z') {
                return (char) c;
            }
            if ('A' <= c && c <= 'Z') {
                return (char) c;
            }
            throw new InputMismatchException();
        }

        public String nextToken() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c-'0';
                c = next();
            } while (!isSpaceChar(c));
            return res*sgn;
        }

        public long nextLong() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c-'0';
                c = next();
            } while (!isSpaceChar(c));
            return res*sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}