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.IOException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Queue;

public class TheseusAndLabyrinth {
	public static final int U = 0;
	public static final int R = 1;
	public static final int D = 2;
	public static final int L = 3;
	
	public static final int[] DX = { -1, 0, 1, 0 };
	public static final int[] DY = { 0, 1, 0, -1 };
	
	public static final boolean[][] MOVE = new boolean[256][4];
	static {
		Arrays.fill(MOVE['+'], true);

		Arrays.fill(MOVE['U'], true);
		Arrays.fill(MOVE['R'], true);
		Arrays.fill(MOVE['D'], true);
		Arrays.fill(MOVE['L'], true);
		MOVE['U'][U] = false;
		MOVE['R'][R] = false;
		MOVE['D'][D] = false;
		MOVE['L'][L] = false;

		MOVE['|'][U] = true;
		MOVE['|'][D] = true;
		MOVE['-'][L] = true;
		MOVE['-'][R] = true;

		MOVE['^'][U] = true;
		MOVE['>'][R] = true;
		MOVE['v'][D] = true;
		MOVE['<'][L] = true;
	}
	
	public static void main(String[] args) {
		FasterScanner sc = new FasterScanner();

		int N = sc.nextInt();
		int M = sc.nextInt();
		
		char[][] A = new char[N][];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLine().toCharArray();
		}
		
		int XT = sc.nextInt() - 1;
		int YT = sc.nextInt() - 1;
		int XM = sc.nextInt() - 1;
		int YM = sc.nextInt() - 1;
		
		int[][][] d = new int[N][M][4];
		for (int x = 0; x < N; x++) {
			for (int y = 0; y < M; y++) {
				Arrays.fill(d[x][y], Integer.MAX_VALUE);
			}
		}

		State init = new State(XT, YT, 0, 0);
		Queue<State> q = new ArrayDeque<State>();
		q.offer(init);
		d[XT][YT][0] = 0;
		while (!q.isEmpty()) {
			State s = q.poll();
			if (s.X == XM && s.Y == YM) {
				System.out.println(s.D);
				return;
			}
			int dist = s.D + 1;
			for (int r = 0; r < DX.length; r++) {
				int actDir = (s.R + r) % 4;
				int b = (r + 2) % 4;
				int x = s.X + DX[actDir];
				int y = s.Y + DY[actDir];
				if (valid(A, x, y) && MOVE[A[s.X][s.Y]][r] && MOVE[A[x][y]][b] && dist < d[x][y][s.R]) {
					State next = new State(x, y, s.R, dist);
					q.offer(next);
					d[x][y][s.R] = dist;
				}
			}
			int rot = (s.R + 1) % 4;
			if (dist < d[s.X][s.Y][rot]) {
				State push = new State(s.X, s.Y, rot, dist);
				q.offer(push);
				d[s.X][s.Y][rot] = dist;
			}
		}
		System.out.println(-1);
	}
	
	public static boolean valid(char[][] A, int x, int y) {
		return (x >= 0 && x < A.length && y >= 0 && y < A[x].length);
	}
	
	public static class State {
		public int X, Y, R, D;
		
		public State(int x, int y, int r, int d) {
			this.X = x;
			this.Y = y;
			this.R = r;
			this.D = d;
		}
	}

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		public int[] nextIntArray(int n, int off) {
			int[] arr = new int[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		public long[] nextLongArray(int n, int off) {
			long[] arr = new long[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}