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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.Queue;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Arthur Petukhovsky petuhovskiy@yandex.ru
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        char[][] c;
        int n;
        int m;
        int xt;
        int yt;
        int xm;
        int ym;
        int[][][] dist;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            c = new char[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    c[i][j] = in.nextChar();
                }
            }
            xt = in.nextInt() - 1;
            yt = in.nextInt() - 1;
            xm = in.nextInt() - 1;
            ym = in.nextInt() - 1;
            dist = new int[n][m][4];
            for (int[][] i1 : dist) {
                for (int[] i2 : i1) {
                    for (int j = 0; j < i2.length; j++) i2[j] = -1;
                }
            }
            dist[xt][yt][0] = 0;
            Queue<State> q = new ArrayDeque<>();
            q.add(new State(xt, yt, 0));
            while (!q.isEmpty()) {
                State s = q.poll();
                //System.err.println(s);
                int cur = dist[s.x][s.y][s.rot];
                if (s.x == xm && s.y == ym) {
                    out.println(cur);
                    return;
                }
                boolean[] can = get(s.x, s.y, s.rot);
                if (can[3]) go(s.x + 1, s.y, s.rot, cur, q, 3);
                if (can[1]) go(s.x - 1, s.y, s.rot, cur, q, 1);
                if (can[2]) go(s.x, s.y + 1, s.rot, cur, q, 2);
                if (can[0]) go(s.x, s.y - 1, s.rot, cur, q, 0);
                go(s.x, s.y, (s.rot + 1) % 4, cur, q, -1);
            }
            out.println(-1);
        }

        private boolean[] get(int x, int y, int rot) {
            boolean[] b = new boolean[4];
            switch (c[x][y]) {
                case '+':
                    b[0] = b[1] = b[2] = b[3] = true;
                    break;
                case '-':
                    b[0] = b[2] = true;
                    break;
                case '|':
                    b[1] = b[3] = true;
                    break;
                case '^':
                    b[1] = true;
                    break;
                case '>':
                    b[2] = true;
                    break;
                case 'v':
                    b[3] = true;
                    break;
                case '<':
                    b[0] = true;
                    break;
                case 'L':
                    b[1] = b[2] = b[3] = true;
                    break;
                case 'U':
                    b[0] = b[2] = b[3] = true;
                    break;
                case 'R':
                    b[1] = b[0] = b[3] = true;
                    break;
                case 'D':
                    b[1] = b[2] = b[0] = true;
                    break;
                case '*':
                    break;
                default:
                    throw new RuntimeException("Went wrong");
            }
            boolean[] tmp = new boolean[4];
            int it = 0;
            rot = (4 - rot) % 4;
            for (int i = rot; i < 4; i++) tmp[it++] = b[i];
            for (int i = 0; i < rot; i++) tmp[it++] = b[i];
            return tmp;
        }

        private void go(int x, int y, int rot, int cur, Queue<State> q, int gop) {
            cur++;
            if (x < 0 || y < 0 || x >= n || y >= m) return;
            boolean[] b = get(x, y, rot);
            if (gop != -1 && !b[(gop + 2) % 4]) return;
            if (dist[x][y][rot] != -1) return;
            dist[x][y][rot] = cur;
            q.add(new State(x, y, rot));
        }

    }

    static class State {
        int x;
        int y;
        int rot;

        State(int x, int y, int rot) {
            this.x = x;
            this.y = y;
            this.rot = rot;
        }


        public String toString() {
            return "State{" +
                    "x=" + x +
                    ", y=" + y +
                    ", rot=" + rot +
                    '}';
        }

    }

    static class FastScanner {
        final static int BUFFER_SIZE = 65536;
        BufferedReader br;
        char[] buf = new char[BUFFER_SIZE];
        int len = 0;
        int it = 0;
        boolean end = false;

        boolean delim(char c) {
            return c == ' ' || c == '\n' || c == '\r';
        }

        void fillBuffer() {
            try {
                len = br.read(buf);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void ensureBuffer() {
            if (it == len) {
                it = 0;
                fillBuffer();
                if (len == -1) end = true;
            }
        }

        void moveNext() {
            while (!end) {
                ensureBuffer();
                if (!delim(buf[it])) return;
                while (it < len && delim(buf[it])) it++;
            }
        }

        public char nextChar() {
            moveNext();
            if (end) throw new NullPointerException("End was reached");
            return buf[it++];
        }

        public int nextInt() {
            moveNext();
            if (buf[it] == '-') {
                it++;
                return -nextInt();
            }
            if (buf[it] == '+') {
                it++;
                return nextInt();
            }
            int result = 0;
            while (!end) {
                int l = it;
                while (it < len && !delim(buf[it])) {
                    result = (result * 10) + buf[it] - '0';
                    it++;
                }
                ensureBuffer();
                if (end || delim(buf[it])) break;
            }
            return result;
        }

        public FastScanner(String file) {
            try {
                br = new BufferedReader(new FileReader(file), BUFFER_SIZE);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is), BUFFER_SIZE);
        }

    }
}