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:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class ProblemD3 {
    BufferedReader rd;

    char[][] c;
    char[][] rotp = new char[4][128];

    ProblemD3() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        int[] a = intarr();
        int n = a[0];
        int m = a[1];
        c = new char[n][];
        for(int i=0;i<n;i++) {
            c[i] = rd.readLine().toCharArray();
        }
        int[] t = intarr();
        t[0]--;
        t[1]--;
        int[] mino = intarr();
        mino[0]--;
        mino[1]--;

        for(int i=0;i<128;i++) {
            rotp[0][i] = (char)i;
        }
        for(char z: "+^v<>LURD*|-".toCharArray()) {
            for(int p=1;p<=3;p++) {
                rotp[p][z] = rot(rotp[p-1][z]);
            }
        }

        int minutes = -1;
        if(t[0] != mino[0] || t[1] != mino[1]) {
            int base = n*m;
            int nodes = base << 2;
            int[][] e = new int[nodes][];
            int[] g = new int[] { 0, 0, 1, -1 };
            int[] h = new int[] { 1, -1, 0, 0 };
            for(int p = 0; p < 4; p++) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < m; j++) {
                        int cur = p * n * m + i * m + j;
                        for (int k = 0; k < 4; k++) {
                            int ro = i + g[k];
                            int co = j + h[k];
                            if (ro >= 0 && ro < n && co >= 0 && co < m) {
                                if(door(i,j,p,k) && door(ro,co,p,k<2?1-k:5-k)) {
                                    int other = p * base + ro * m + co;
                                    x(e,cur,other);
                                    x(e,other,cur);
                                }
                            }
                        }
                        int np = (p + 1)%4;
                        int other = np * base + i * m + j;
                        x(e,cur,other);
                    }
                }
            }

            Queue<Integer> q = new ArrayDeque<>();
            boolean[] vis = new boolean[nodes];
            int[] d = new int[nodes];
            Arrays.fill(d, Integer.MAX_VALUE);
            int start = t[0]*m+t[1];
            q.add(start);
            d[start] = 0;
            vis[start] = true;
            while(!q.isEmpty()) {
                int v = q.poll();
                for(int u: e[v]) {
                    if(!vis[u]) {
                        vis[u] = true;
                        q.add(u);
                        d[u] = d[v]+1;
                    }
                }
            }
            int dest = mino[0]*m+mino[1];
            for(int p=0;p<4;p++) {
                int v = p*base + dest;
                if(d[v] != Integer.MAX_VALUE) {
                    if (minutes == -1) {
                        minutes = d[v];
                    } else {
                        minutes = Math.min(minutes, d[v]);
                    }
                }
            }
        } else {
            minutes = 0;
        }
        out(minutes);
    }

    private void x(int[][] e, int cur, int other) {
        int[] u = e[cur];
        int[] z;
        if(u == null) {
            z = new int[] { other };
        } else {
            z = Arrays.copyOf(u, u.length + 1);
            z[u.length] = other;
        }
        e[cur] = z;
    }

    private boolean door(int i, int j, int p, int k) {
        char d = rotp[p][c[i][j]];
        switch(d) {
            case '+':
                return true;
            case '|':
                return k > 1;
            case '-':
                return k < 2;
            case '^':
                return k == 3;
            case 'v':
                return k == 2;
            case '>':
                return k == 0;
            case '<':
                return k == 1;
            case 'L':
                return k != 1;
            case 'R':
                return k != 0;
            case 'U':
                return k != 3;
            case 'D':
                return k != 2;
            default:
                return false;
        }
    }

    private char rot(char x) {
        switch(x) {
            case '-':
                return '|';
            case '|':
                return '-';
            case '^':
                return '>';
            case '>':
                return 'v';
            case 'v':
                return '<';
            case '<':
                return '^';
            case 'L':
                return 'U';
            case 'R':
                return 'D';
            case 'U':
                return 'R';
            case 'D':
                return 'L';
            default:
                return x;
        }
    }

    private int[] intarr() throws IOException {
        return intarr(rd.readLine());
    }

    private int[] intarr(String s) {
        String[] q = split(s);
        int n = q.length;
        int[] a = new int[n];
        for(int i=0;i<n;i++) {
            a[i] = Integer.parseInt(q[i]);
        }
        return a;
    }

    public String[] split(String s) {
        if(s == null) {
            return new String[0];
        }
        int n = s.length();
        int start = -1;
        int end = 0;
        int sp = 0;
        boolean lastWhitespace = true;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(isWhitespace(c)) {
                lastWhitespace = true;
            } else {
                if(lastWhitespace) {
                    sp++;
                }
                if(start == -1) {
                    start = i;
                }
                end = i;
                lastWhitespace = false;
            }
        }
        if(start == -1) {
            return new String[0];
        }
        String[] res = new String[sp];
        int last = start;
        int x = 0;
        lastWhitespace = true;
        for(int i=start;i<=end;i++) {
            char c = s.charAt(i);
            boolean w = isWhitespace(c);
            if(w && !lastWhitespace) {
                res[x++] = s.substring(last,i);
            } else if(!w && lastWhitespace) {
                last = i;
            }
            lastWhitespace = w;
        }
        res[x] = s.substring(last,end+1);
        return res;
    }

    private boolean isWhitespace(char c) {
        return c==' ' || c=='\t';
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new ProblemD3();
    }
}