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.util.*;

public class D676 {
    final static int N = 1;
    final static int E = 2;
    final static int S = 4;
    final static int W = 8;
    /** Circular shift, clockwise: N -> E -> S -> W -> N
     * n should b at most 4 (identity) */
    static int cs(int x, int n) {
        x <<= n;
        x |= x >> 4;
        x &= 0xf;
        return x;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int h = in.nextInt();
        int w = in.nextInt();
        int[][] a = new int[h][w];
        for (int y = 0; y < h; y++) {
            char[] row = in.next().toCharArray();
            //System.err.println(Arrays.toString(row));
            for (int x = 0; x < w; x++) {
                switch(row[x]) {
                    case '+': a[y][x] = N|E|W|S; break;
                    case '-': a[y][x] = E|W; break;
                    case '|': a[y][x] = N|S; break;
                    case '^': a[y][x] = N; break;
                    case '>': a[y][x] = E; break;
                    case '<': a[y][x] = W; break;
                    case 'v': a[y][x] = S; break;
                    case 'U': a[y][x] = E|S|W; break;
                    case 'R': a[y][x] = N|S|W; break;
                    case 'D': a[y][x] = N|E|W; break;
                    case 'L': a[y][x] = N|E|S; break;
                    case '*': a[y][x] = 0; break;
                    default: break;
                }
            }
        }
        int yt = in.nextInt()-1;
        int xt = in.nextInt()-1;
        int ym = in.nextInt()-1;
        int xm = in.nextInt()-1;

        int dist[] = new int[max*max*4];
        int inf = dist.length;
        Arrays.fill(dist, inf);
        Queue<Node> q = new ArrayDeque<Node>();
        Node start = new Node(xt,yt,0);
        dist[start.id] = 0;
        q.add(start);

        while (!q.isEmpty()) {
            Node n = q.poll();

            List<Node> ns = new ArrayList<Node>();
            int x = n.x, y = n.y, r = n.r;
            ns.add(new Node(x, y, (r+1)%4));
            if (x+1 < w  && (cs(a[y][x],r) & E) != 0 && (cs(a[y][x+1],r) & W) != 0) ns.add(new Node(x+1, y, r));
            if (x-1 >= 0 && (cs(a[y][x],r) & W) != 0 && (cs(a[y][x-1],r) & E) != 0) ns.add(new Node(x-1, y, r));
            if (y+1 < h  && (cs(a[y][x],r) & S) != 0 && (cs(a[y+1][x],r) & N) != 0) ns.add(new Node(x, y+1, r));
            if (y-1 >= 0 && (cs(a[y][x],r) & N) != 0 && (cs(a[y-1][x],r) & S) != 0) ns.add(new Node(x, y-1, r));

            for (Node next : ns) {
                if (dist[next.id] == inf) {
                    dist[next.id] = dist[n.id]+1;
                    q.add(next);
                }
            }
        }

        int best = inf;
        for (int r = 0; r < 4; r++) {
            Node mino = new Node(xm, ym, r);
            best = Math.min(best, dist[mino.id]);
        }
        if (best == inf)
            best = -1;
        System.out.println(best);
    }
    final static int inf = 1<<30;
    final static int max = 1000+1;
    static class Node {
        Node (int x, int y, int r) {
            this.x = x;
            this.y = y;
            this.r = r;
            id = 4*max*x + 4*y + r;
        }
        int x;
        int y;
        int r;
        int id;
    }
}