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.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


public class D676 {
	static int[][][] memo;
	static int oo = 987654321;
	public static void main(String[] args) {
		MyScanner scan = new MyScanner();
		
		int N = scan.nextInt(), M = scan.nextInt();
		
		int[] dr = {-1,0,1,0}, dc = {0,1,0,-1};
		memo = new int[N][M][4];
		
		char[][] map = new char[N][M];
		for(int i=0;i<N;i++){
			String line = scan.next();
			for(int j=0;j<M;j++){
				map[i][j] = line.charAt(j);
				Arrays.fill(memo[i][j], oo);
			}
		}
		int sR = scan.nextInt()-1, sC = scan.nextInt()-1, eR = scan.nextInt()-1, eC = scan.nextInt()-1;
		memo[sR][sC][0] = 0;
		
		PriorityQueue<Node> q = new PriorityQueue<>();
		q.add(new Node(sR, sC, 0));
		while(!q.isEmpty()){
			Node t = q.poll();
			int r = t.r, c = t.c, delta = t.delta;
			
			for(int i=1;i<4;i++){
				if(memo[r][c][(delta+i)%4] > memo[r][c][delta]+i){
					memo[r][c][(delta+i)%4] = memo[r][c][delta]+i;
					q.add(new Node(r, c, (delta+i)%4));
				}
			}
			
			//up
			if(up(map, r, c)){
				if(r+dr[delta]>=0 && r+dr[delta]<N && c+dc[delta]>=0 && c+dc[delta]<M && down(map, r+dr[delta], c+dc[delta])){
					if(memo[r+dr[delta]][c+dc[delta]][delta] > memo[r][c][delta]+1){
						memo[r+dr[delta]][c+dc[delta]][delta] = memo[r][c][delta]+1;
						q.add(new Node(r+dr[delta], c+dc[delta], delta));
					}
				}
			}
			if(right(map,r,c)){
				if(r+dr[(1+delta)%4]>=0 && r+dr[(1+delta)%4]<N && c+dc[(1+delta)%4]>=0 && c+dc[(1+delta)%4]<M && left(map, r+dr[(1+delta)%4], c+dc[(1+delta)%4])){
					if(memo[r+dr[(1+delta)%4]][c+dc[(1+delta)%4]][delta] > memo[r][c][delta]+1){
						memo[r+dr[(1+delta)%4]][c+dc[(1+delta)%4]][delta] = memo[r][c][delta]+1;
						q.add(new Node(r+dr[(1+delta)%4], c+dc[(1+delta)%4], delta));
					}
				}
			}
			if(down(map,r,c)){
				if(r+dr[(2+delta)%4]>=0 && r+dr[(2+delta)%4]<N && c+dc[(2+delta)%4]>=0 && c+dc[(2+delta)%4]<M && up(map, r+dr[(2+delta)%4], c+dc[(2+delta)%4])){
					if(memo[r+dr[(2+delta)%4]][c+dc[(2+delta)%4]][delta] > memo[r][c][delta]+1){
						memo[r+dr[(2+delta)%4]][c+dc[(2+delta)%4]][delta] = memo[r][c][delta]+1;
						q.add(new Node(r+dr[(2+delta)%4], c+dc[(2+delta)%4], delta));
					}
				}
			}
			if(left(map,r,c)){
				if(r+dr[(3+delta)%4]>=0 && r+dr[(3+delta)%4]<N && c+dc[(3+delta)%4]>=0 && c+dc[(3+delta)%4]<M && right(map, r+dr[(3+delta)%4], c+dc[(3+delta)%4])){
					if(memo[r+dr[(3+delta)%4]][c+dc[(3+delta)%4]][delta] > memo[r][c][delta]+1){
						memo[r+dr[(3+delta)%4]][c+dc[(3+delta)%4]][delta] = memo[r][c][delta]+1;
						q.add(new Node(r+dr[(3+delta)%4], c+dc[(3+delta)%4], delta));
					}
				}
			}
		}
		
		int min = Math.min(Math.min(memo[eR][eC][0], memo[eR][eC][1]), Math.min(memo[eR][eC][2], memo[eR][eC][3]));
		System.out.println(min==oo?"-1":min);
		
		
	}
	private static boolean up(char[][] map, int r, int c) {
		return map[r][c]=='+'||map[r][c]=='|'||map[r][c]=='^'||map[r][c]=='L'||map[r][c]=='R'||map[r][c]=='D';
	}
	private static boolean down(char[][] map, int r, int c) {
		return map[r][c]=='+'||map[r][c]=='|'||map[r][c]=='v'||map[r][c]=='L'||map[r][c]=='R'||map[r][c]=='U';
	}
	private static boolean left(char[][] map, int r, int c) {
		return map[r][c]=='+'||map[r][c]=='-'||map[r][c]=='<'||map[r][c]=='U'||map[r][c]=='R'||map[r][c]=='D';
	}
	private static boolean right(char[][] map, int r, int c) {
		return map[r][c]=='+'||map[r][c]=='-'||map[r][c]=='>'||map[r][c]=='L'||map[r][c]=='U'||map[r][c]=='D';
	}
	
	private static class Node implements Comparable<Node>{
		int r, c, delta;
		public Node(int r, int c, int delta) {
			this.r = r;
			this.c = c;
			this.delta = delta;
		}
		public int compareTo(Node o) {
			return Integer.compare(memo[this.r][this.c][this.delta], memo[o.r][o.c][o.delta]);
		}
	}
	private static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}