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 baobab;

import java.io.*;
import java.util.*;

public class D {

    public static void main(String[] args) {
        DIO io = new DIO();
        try {
            Dsolver solver = new Dsolver(io);
            io.println(solver.solve());
        } finally {
            io.close();
        }
    }

}

class Dsolver {
    DIO io;

    boolean[][][] hasDoor;

    static final int UP = 0;
    static final int RIGHT = 1;
    static final int DOWN = 2;
    static final int LEFT = 3;

    public Dsolver(DIO io) {
        this.io = io;
    }

    public int solve() {
        int n = io.nextInt();
        int m = io.nextInt();
        hasDoor = new boolean[4][n][m];
        for (int y=0; y<n; y++) {
            String line = io.next();
            for (int x=0; x<m; x++) {
                char c = line.charAt(x);
                switch (c) {
                    case '+':
                        hasDoor[0][y][x] = true;
                        hasDoor[1][y][x] = true;
                        hasDoor[2][y][x] = true;
                        hasDoor[3][y][x] = true;
                        break;
                    case '-':
                        hasDoor[1][y][x] = true;
                        hasDoor[3][y][x] = true;
                        break;
                    case '|':
                        hasDoor[0][y][x] = true;
                        hasDoor[2][y][x] = true;
                        break;
                    case '^':
                        hasDoor[0][y][x] = true;
                        break;
                    case '>':
                        hasDoor[1][y][x] = true;
                        break;
                    case '<':
                        hasDoor[3][y][x] = true;
                        break;
                    case 'v':
                        hasDoor[2][y][x] = true;
                        break;
                    case 'L':
                        hasDoor[0][y][x] = true;
                        hasDoor[1][y][x] = true;
                        hasDoor[2][y][x] = true;
                        break;
                    case 'R':
                        hasDoor[0][y][x] = true;
                        hasDoor[2][y][x] = true;
                        hasDoor[3][y][x] = true;
                        break;
                    case 'U':
                        hasDoor[1][y][x] = true;
                        hasDoor[2][y][x] = true;
                        hasDoor[3][y][x] = true;
                        break;
                    case 'D':
                        hasDoor[0][y][x] = true;
                        hasDoor[1][y][x] = true;
                        hasDoor[3][y][x] = true;
                        break;
                    case '*':
                        // no doors
                        break;
                    default:
                        break;
                }
            }
        }
        int startY = io.nextInt() - 1;
        int startX = io.nextInt() - 1;
        int goalY = io.nextInt() - 1;
        int goalX = io.nextInt() - 1;
        if (startX == goalX && startY == goalY) return 0;
        boolean[][][] visited = new boolean[4][n][m];
        ArrayDeque<Block> q = new ArrayDeque<>();
        q.add(new Block(0, startY, startX, 0));
        while (!q.isEmpty()) {
            Block b = q.pollFirst();
            //System.out.println("VISITED: " + b.rotation + " rot, y = " + b.y + " x = " + b.x);
            if (visited[b.rotation][b.y][b.x]) continue;
            visited[b.rotation][b.y][b.x] = true;
            if (b.y == goalY && b.x == goalX) return b.steps;


            q.add(new Block((b.rotation + 1) % 4, b.y, b.x, b.steps + 1)); // rotate

            Block goUp = new Block(b.rotation, b.y - 1, b.x, b.steps + 1);
            if (b.y > 0 && doors(b, goUp, UP, DOWN)) q.addLast(goUp);

            Block goLeft = new Block(b.rotation, b.y, b.x - 1, b.steps + 1);
            if (b.x > 0 && doors(b, goLeft, LEFT, RIGHT)) q.addLast(goLeft);

            Block goDown = new Block(b.rotation, b.y + 1, b.x, b.steps + 1);
            if (b.y < n-1 && doors(b, goDown, DOWN, UP)) q.addLast(goDown);

            Block goRight = new Block(b.rotation, b.y, b.x + 1, b.steps + 1);
            if (b.x < m-1 && doors(b, goRight, RIGHT, LEFT)) q.addLast(goRight);
        }
        return -1;
    }

    private boolean doors(Block origin, Block target, int requiredOriginDoor, int requiredTargetDoor) {
        int modRotO = (requiredOriginDoor - origin.rotation + 4) % 4;
        int modRotT = (requiredTargetDoor - target.rotation + 4) % 4;
        return hasDoor[modRotO][origin.y][origin.x] && hasDoor[modRotT][target.y][target.x];
    }


}

class Block {
    int rotation;
    int y;
    int x;
    int steps;

    public Block(int rotation, int y, int x, int steps) {
        this.rotation = rotation;
        this.steps = steps;
        this.y = y;
        this.x = x;
    }
}

class DIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public DIO() {
        super(new BufferedOutputStream(System.out));
        r = new InputStreamReader(System.in);

        buf = new char[BUFSIZE];
        bufc = 0;
        bufi = 0;
        sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
        bufi = 0;
        bufc = 0;
        while(bufc == 0) {
            bufc = r.read(buf, 0, BUFSIZE);
            if(bufc == -1) {
                bufc = 0;
                return;
            }
        }
    }

    private boolean pumpBuf() throws IOException {
        if(bufi == bufc) {
            fillBuf();
        }
        return bufc != 0;
    }

    private boolean isDelimiter(char c) {
        return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
        while(true) {
            if(bufi == bufc) {
                fillBuf();
                if(bufc == 0) throw new RuntimeException("IO: Out of input.");
            }

            if(!isDelimiter(buf[bufi])) break;
            ++bufi;
        }
    }

    public String next() {
        try {
            sb.setLength(0);

            eatDelimiters();
            int start = bufi;

            while(true) {
                if(bufi == bufc) {
                    sb.append(buf, start, bufi - start);
                    fillBuf();
                    start = 0;
                    if(bufc == 0) break;
                }

                if(isDelimiter(buf[bufi])) break;
                ++bufi;
            }

            sb.append(buf, start, bufi - start);

            return sb.toString();
        } catch(IOException e) {
            throw new RuntimeException("IO.next: Caught IOException.");
        }
    }

    public int nextInt() {
        try {
            int ret = 0;

            eatDelimiters();

            boolean positive = true;
            if(buf[bufi] == '-') {
                ++bufi;
                if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                positive = false;
            }

            boolean first = true;
            while(true) {
                if(!pumpBuf()) break;
                if(isDelimiter(buf[bufi])) {
                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                    break;
                }
                first = false;

                if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                    ret *= 10;
                    ret -= (int)(buf[bufi] - '0');
                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                } else {
                    throw new RuntimeException("IO.nextInt: Invalid int.");
                }

                ++bufi;
            }

            if(positive) {
                if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                ret = -ret;
            }

            return ret;
        } catch(IOException e) {
            throw new RuntimeException("IO.nextInt: Caught IOException.");
        }
    }

    public long nextLong() {
        try {
            long ret = 0;

            eatDelimiters();

            boolean positive = true;
            if(buf[bufi] == '-') {
                ++bufi;
                if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                positive = false;
            }

            boolean first = true;
            while(true) {
                if(!pumpBuf()) break;
                if(isDelimiter(buf[bufi])) {
                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                    break;
                }
                first = false;

                if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                    ret *= 10;
                    ret -= (long)(buf[bufi] - '0');
                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                } else {
                    throw new RuntimeException("IO.nextLong: Invalid long.");
                }

                ++bufi;
            }

            if(positive) {
                if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                ret = -ret;
            }

            return ret;
        } catch(IOException e) {
            throw new RuntimeException("IO.nextLong: Caught IOException.");
        }
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}