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.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;

public class D {

	static class State {
		int x, y, r;

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

		@Override
		public String toString() {
			return "[x=" + x + ", y=" + y + ", r=" + r + "]";
		}

	}

	static final int INF = Integer.MAX_VALUE;
	static Map<Character, boolean[]> l;
	static int[][] dir = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };

	static int rows, cols, x0, y0, x1, y1;
	static char[][] m;

	static int[][][] d;
	static boolean[][][] v;

	static boolean check(int r, int c) {
		return r >= 0 && r < rows && c >= 0 && c < cols;
	}

	static boolean move(int r0, int c0, int di, int r) {
		if (!check(r0 + dir[di][0], c0 + dir[di][1]))
			return false;
		boolean[] w = l.get(m[r0][c0]);
		int idDoor = (di - r + 4) % 4;
		if (!w[idDoor])
			return false;
		w = l.get(m[r0 + dir[di][0]][c0 + dir[di][1]]);
		idDoor = (((di + 2) % 4) - r + 4) % 4;
		if (!w[idDoor])
			return false;
		// if (d[r0][c0][r] + 1 > d[r0 + dir[di][0]][c0 + dir[di][1]][r])
		if (v[r0 + dir[di][0]][c0 + dir[di][1]][r])
			return false;
		return true;
	}

	static int bfs() {
		Queue<State> q = new ArrayDeque<>();
		State u = new State(x0, y0, 0);
		q.add(u);
		while (!q.isEmpty()) {
			u = q.poll();
			if (v[u.x][u.y][u.r])
				continue;
			v[u.x][u.y][u.r] = true;
			if (u.x == x1 && u.y == y1)
				return d[u.x][u.y][u.r];
			for (int i = 0; i < dir.length; i++) {
				if (move(u.x, u.y, i, u.r)) {
					d[u.x + dir[i][0]][u.y + dir[i][1]][u.r] = d[u.x][u.y][u.r] + 1;
					q.add(new State(u.x + dir[i][0], u.y + dir[i][1], u.r));
				}
			}
			// if (d[u.x][u.y][(u.r + 1) % 4] > d[u.x][u.y][u.r] + 1) {
			if (!v[u.x][u.y][(u.r + 1) % 4]) {
				d[u.x][u.y][(u.r + 1) % 4] = d[u.x][u.y][u.r] + 1;
				q.add(new State(u.x, u.y, (u.r + 1) % 4));
			}
		}
		return -1;
	}

	public static void main(String[] args) throws IOException {
		File inputFile = new File("entradaD");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		l = new HashMap<>();
		// «+» 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.
		l.put('+', new boolean[] { true, true, true, true });
		l.put('-', new boolean[] { false, true, false, true });
		l.put('|', new boolean[] { true, false, true, false });
		l.put('^', new boolean[] { true, false, false, false });
		l.put('>', new boolean[] { false, true, false, false });
		l.put('v', new boolean[] { false, false, true, false });
		l.put('<', new boolean[] { false, false, false, true });
		l.put('U', new boolean[] { false, true, true, true });
		l.put('R', new boolean[] { true, false, true, true });
		l.put('D', new boolean[] { true, true, false, true });
		l.put('L', new boolean[] { true, true, true, false });
		l.put('*', new boolean[] { false, false, false, false });
		while ((line = in.readLine()) != null) {
			int[] nm = readInts(line);
			rows = nm[0];
			cols = nm[1];
			m = new char[rows][cols];
			d = new int[rows][cols][4];
			v = new boolean[rows][cols][4];
			for (int i = 0; i < rows; i++) {
				m[i] = in.readLine().toCharArray();
				for (int j = 0; j < cols; j++)
					for (int k = 0; k < 4; k++)
						d[i][j][k] = INF;
			}
			int[] xy = readInts(in.readLine());
			x0 = xy[0] - 1;
			y0 = xy[1] - 1;
			xy = readInts(in.readLine());
			x1 = xy[0] - 1;
			y1 = xy[1] - 1;
			d[x0][y0][0] = 0;
			int ans = bfs();
			out.append(ans + "\n");
		}
		System.out.print(out);
	}

	static int[] readInts(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		int a[] = new int[st.countTokens()], index = 0;
		while (st.hasMoreTokens())
			a[index++] = Integer.parseInt(st.nextToken());
		return a;
	}

	static long[] readLongs(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		long a[] = new long[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Long.parseLong(st.nextToken());
		return a;
	}

	static double[] readDoubles(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		double a[] = new double[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Double.parseDouble(st.nextToken());
		return a;
	}
}