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

public class Solution {

    static final String UP = "+|^LRD";
    static final String DOWN = "+|vLRU";
    static final String RIGHT = "+->LDU";
    static final String LEFT = "+-<RDU";

    static char rotate(char c) {
        switch (c) {
            case '+':
                return '+';

            case '-':
                return '|';

            case '|':
                return '-';

            case '^':
                return '>';

            case '>':
                return 'v';

            case 'v':
                return '<';

            case '<':
                return '^';

            case 'L':
                return 'U';

            case 'U':
                return 'R';

            case 'R':
                return 'D';

            case 'D':
                return 'L';

            default:
                return '*';
        }
    }

    static class Node {
        int i;
        int j;
        int k;

        public Node(int i, int j, int k) {
            this.i = i;
            this.j = j;
            this.k = k;
        }
    }

    static boolean up(Node node, char[][][] c, int[][][] a) {
        int i = node.i, j = node.j, k = node.k;
        if (i == 0 || a[i - 1][j][k] != Integer.MAX_VALUE)
            return false;

        if (UP.contains(c[i][j][k] + "") && DOWN.contains(c[i - 1][j][k] + ""))
            return true;
        else
            return false;
    }

    static boolean down(Node node, char[][][] c, int[][][] a) {
        int i = node.i, j = node.j, k = node.k;
        if (i == a.length - 1 || a[i + 1][j][k] != Integer.MAX_VALUE)
            return false;

        if (DOWN.contains(c[i][j][k] + "") && UP.contains(c[i + 1][j][k] + ""))
            return true;
        else
            return false;
    }

    static boolean left(Node node, char[][][] c, int[][][] a) {
        int i = node.i, j = node.j, k = node.k;
        if (j == 0 || a[i][j - 1][k] != Integer.MAX_VALUE)
            return false;

        if (LEFT.contains(c[i][j][k] + "") && RIGHT.contains(c[i][j - 1][k] + ""))
            return true;
        else
            return false;
    }

    static boolean right(Node node, char[][][] c, int[][][] a) {
        int i = node.i, j = node.j, k = node.k;
        if (j == a[i].length - 1 || a[i][j + 1][k] != Integer.MAX_VALUE)
            return false;

        if (RIGHT.contains(c[i][j][k] + "") && LEFT.contains(c[i][j + 1][k] + ""))
            return true;
        else
            return false;
    }

    static boolean through(Node node, int[][][] a) {
        int i = node.i, j = node.j, k = (node.k + 1) % 4;
        if (a[i][j][k] == Integer.MAX_VALUE)
            return true;
        else
            return false;
    }

    static void solve(InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();

        char[][][] c = new char[n][m][4];
        for (int i = 0; i < n; i++) {
            String s = in.next();

            for (int j = 0; j < s.length(); j++) {
                c[i][j][0] = s.charAt(j);
                c[i][j][1] = rotate(c[i][j][0]);
                c[i][j][2] = rotate(c[i][j][1]);
                c[i][j][3] = rotate(c[i][j][2]);
            }
        }

        int xt = in.nextInt() - 1;
        int yt = in.nextInt() - 1;
        int xm = in.nextInt() - 1;
        int ym = in.nextInt() - 1;

        if (xt == xm && yt == ym) {
            out.print(0);
            return;
        }

        int[][][] a = new int[n][m][4];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                for (int k = 0; k < 4; k++)
                    a[i][j][k] = Integer.MAX_VALUE;

        a[xt][yt][0] = 0;
        Queue<Node> queue = new LinkedList<Node>();
        queue.add(new Node(xt, yt, 0));

        while (!queue.isEmpty()) {
            Node node = queue.remove();

            if (up(node, c, a)) {
                a[node.i - 1][node.j][node.k] = a[node.i][node.j][node.k] + 1;
                queue.add(new Node(node.i - 1, node.j, node.k));
            }

            if (right(node, c, a)) {
                a[node.i][node.j + 1][node.k] = a[node.i][node.j][node.k] + 1;
                queue.add(new Node(node.i, node.j + 1, node.k));
            }

            if (down(node, c, a)) {
                a[node.i + 1][node.j][node.k] = a[node.i][node.j][node.k] + 1;
                queue.add(new Node(node.i + 1, node.j, node.k));
            }

            if (left(node, c, a)) {
                a[node.i][node.j - 1][node.k] = a[node.i][node.j][node.k] + 1;
                queue.add(new Node(node.i, node.j - 1, node.k));
            }

            if (through(node, a)) {
                a[node.i][node.j][(node.k + 1) % 4] = a[node.i][node.j][node.k] + 1;
                queue.add(new Node(node.i, node.j, (node.k + 1) % 4));
            }
        }

        int ans = Math.min(Math.min(a[xm][ym][0], a[xm][ym][1]), Math.min(a[xm][ym][2], a[xm][ym][3]));
        if (ans == Integer.MAX_VALUE)
            out.print(-1);
        else
            out.print(ans);
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        solve(in, out);
        in.close();
        out.close();
    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        InputReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        String nextLine() {
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return line;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) return null;
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    static class OutputWriter {
        BufferedWriter bw;

        OutputWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        void print(int i) {
            print(Integer.toString(i));
        }

        void println(int i) {
            println(Integer.toString(i));
        }

        void print(long l) {
            print(Long.toString(l));
        }

        void println(long l) {
            println(Long.toString(l));
        }

        void print(double d) {
            print(Double.toString(d));
        }

        void println(double d) {
            println(Double.toString(d));
        }

        void print(boolean b) {
            print(Boolean.toString(b));
        }

        void println(boolean b) {
            println(Boolean.toString(b));
        }

        void print(char c) {
            try {
                bw.write(c);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(char c) {
            println(Character.toString(c));
        }

        void print(String s) {
            try {
                bw.write(s);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(String s) {
            print(s);
            print('\n');
        }

        void close() {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}