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.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class cf676dd {
	static char[][] grid;
	static char change (char o, int k) {
		k %= 4;
		if (k==0) {
			return o;
		}
		if (k==1) {
			switch (o) {
			case ('<'): return '^';
			case ('^'): return '>';
			case ('>'): return 'v';
			case ('v'): return '<';
			case ('L'): return 'U';
			case ('U'): return 'R';
			case ('R'): return 'D';
			case ('D'): return 'L';
			case ('+'): return '+';
			case ('*'): return '*';
			case ('-'): return '|';
			case ('|'): return '-';
			}
		}
		if (k==2) {
			switch (o) {
			case ('<'): return '>';
			case ('^'): return 'v';
			case ('>'): return '<';
			case ('v'): return '^';
			case ('L'): return 'R';
			case ('U'): return 'D';
			case ('R'): return 'L';
			case ('D'): return 'U';
			case ('+'): return '+';
			case ('*'): return '*';
			case ('-'): return '-';
			case ('|'): return '|';
			}
		}
		if (k==3) {
			switch (o) {
			case ('<'): return 'v';
			case ('^'): return '<';
			case ('>'): return '^';
			case ('v'): return '>';
			case ('L'): return 'D';
			case ('U'): return 'L';
			case ('R'): return 'U';
			case ('D'): return 'R';
			case ('+'): return '+';
			case ('*'): return '*';
			case ('-'): return '|';
			case ('|'): return '-';
			}
		}
		return o;
	}
	static boolean can(int x1, int y1,int x2,int y2,int k) {
		if (x1<0 || x2<0 || y1<0 || y2<0 ||x1>=grid.length || y1>= grid[0].length || 
				x2>=grid.length || y2>= grid[0].length) {
			return false;
		}
		if (y1==y2) {
			if (x1>x2) {
				return can(x2,y2,x1,y1,k);
			}
			char ctbd = change(grid[x1][y1],k);
			char ctbu = change(grid[x2][y2],k);
			return (ctbd=='v'||ctbd=='+'||ctbd=='|'||ctbd=='U'||ctbd=='R'||ctbd=='L') &&
					(ctbu=='^'||ctbu=='+'||ctbu=='|'||ctbu=='R'||ctbu=='D'||ctbu=='L');
		}
		else if(x1==x2) {
			if (y1>y2) {
				return can (x2,y2,x1,y1,k);
			}
			char ctbr = change(grid[x1][y1],k);
			char ctbl = change(grid[x2][y2],k);
			return (ctbr=='>'||ctbr=='+'||ctbr=='-'||ctbr=='U'||ctbr=='L'||ctbr=='D') &&
					(ctbl=='<'||ctbl=='+'||ctbl=='-'||ctbl=='U'||ctbl=='R'||ctbl=='D');
		}
		return false;
	}
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st;
		int[] dx = {0,0,-1,1};
		int[] dy = {-1,1,0,0};
		st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		grid = new char[n][m];
		for (int i=0;i<n;i++) {
			grid[i]=br.readLine().toCharArray();
		}
		st = new StringTokenizer(br.readLine());
		int xt = Integer.parseInt(st.nextToken())-1;
		int yt = Integer.parseInt(st.nextToken())-1;
		st = new StringTokenizer(br.readLine());
		int xd = Integer.parseInt(st.nextToken())-1;
		int yd = Integer.parseInt(st.nextToken())-1;
		
		LinkedList<Integer> qx = new LinkedList<>();
		LinkedList<Integer> qy = new LinkedList<>();
		LinkedList<Integer> qr = new LinkedList<>();
		LinkedList<Integer> ql = new LinkedList<>();
		boolean [][][] vis = new boolean[n][m][4];
//		int lv = -1;
		qx.add(xt);
		qy.add(yt);
		qr.add(0);
		ql.add(0);
		int ans = Integer.MAX_VALUE;
		boolean flag = false;
		while (!qx.isEmpty()) {
			int qs = qx.size();
//			lv++;
			while (qs-->0) {
				int x = qx.poll();
				int y = qy.poll();
				int r = qr.poll();
				int l = ql.poll();
//				System.out.println(x+" "+y+" "+r+" "+lv);
//				vis[x][y][r]=true;
				if (x==xd && y==yd) {
					System.out.println(l);
//					flag = true;
//					ans = Math.min(ans, r+lv);
					return;
				}
				
				for (int i=0;i<dx.length;i++) {
//					for (int p=0;p<=3;p++) {
						int xx = x+dx[i]; 
						int yy = y+dy[i];
						
						if (can(x,y,xx,yy,r)&& !vis[xx][yy][r] ) {
//							System.out.printf("%d %d %d %d %d\n",x,y,xx,yy,r);
							qx.add(xx);
							qy.add(yy);
//							qr.add((r+p)%4);
							qr.add(r%4);
							ql.add(l+1);
//							break;
							vis[xx][yy][r%4]=true;
						}
//					}
				}
				if (!vis[x][y][(r+1)%4]) {
					qx.add(x);qy.add(y);qr.add( (r+1) % 4 );ql.add(l+1);
					vis[x][y][(r+1)%4]=true;
				}
				
			}
//			if (flag) {
//				System.out.println(ans);
//				return;
//			}
		}
		System.out.println(-1);
			
		
	}
}