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.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Solution{
	
	static int n, m;
	static int[][] a;
	static int dist[][][];
	static ArrayDeque<int[]> q;
	static int[] dx = {-1, 0, 1, 0};
	static int[] dy = {0, 1, 0, -1};
	static final int inf = (int)1e9+100;
	

	
	
    public static void main(String[] args) throws IOException {
    	
		
    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);
    		
    	int tt = 1;
    	while(tt-->0) {

    		n = fs.nextInt(); m = fs.nextInt();
    		dist = new int[n][m][4];     //dist[x][y][orientation]
    		for(int i=0;i<n;i++) for(int j=0;j<m;j++) for(int d=0;d<4;d++) dist[i][j][d] = inf;
    		
    		a = new int[n][m];
    		
    		for(int i=0;i<n;i++) {
    			char[] s = fs.next().toCharArray();
    			for(int j=0;j<m;j++) {
    				a[i][j] = getMask(s[j]);
    			}
    		}
    		
    		int sx = fs.nextInt()-1, sy = fs.nextInt()-1;
    		int fx = fs.nextInt()-1, fy = fs.nextInt()-1;
    		
    		dist[sx][sy][0] = 0;
    		
    		q = new ArrayDeque<>();
    		q.add(new int[] {sx, sy, 0});
    		
    		
    		while(!q.isEmpty()) {
    			int[] ar = q.pollFirst();
    			int x = ar[0], y = ar[1], or = ar[2];
    			update(x, y, (or+1)%4, dist[x][y][or]+1);
    			for(int dir=0;dir<4;dir++) {
    				if(canGo(x, y, or, dir)) {
    					int nx = x + dx[dir];
    					int ny = y + dy[dir];
    					update(nx, ny, or, dist[x][y][or]+1);
    				}
    			}
    		}
    		
    		int ans = inf;
    		for(int d=0;d<4;d++)
    			ans = Math.min(ans, dist[fx][fy][d]);
    		
    		
    		if(ans==inf) {
    			out.println(-1);
    		}
    		else {
    			out.println(ans);
    		}
    		
    		
    		
    		
    		
    		
    		
    		
    	}
    	
    	out.close();
    		
    }
    
    
    static void update(int x,int y, int or, int ans) {
    	if(dist[x][y][or]==inf) {
    		dist[x][y][or] = ans;
    		q.add(new int[] {x, y, or});
    	}
    		
    }
    
    
    
    static boolean canGo(int x,int y, int or, int dir) {
    	int nx = x + dx[dir], ny = y + dy[dir];
    	if(!isInside(nx, ny)) return false;
    	return hasDoor(x, y, or, dir) && hasDoor(nx, ny, or, dir^2);
    	
    }
    
    static boolean hasDoor(int x, int y, int or, int dir) {
    	dir = (dir-or+4)%4;
    	return ((a[x][y]>>dir)&1)==1?true:false;
    }
    
    static boolean isInside(int x, int y) {
    	return x>=0 && x<n && y>=0 && y<m;
    }
    
    
   
    static int getMask(char ch) {
    	switch(ch) {
    	case '*': return 0;
    	case '+': return 15;
    	case '-': return 10;
    	case '|': return 5;
    	case '^': return 1;
    	case '>': return 2;
    	case 'v': return 4;
    	case '<': return 8;
    	case 'L': return 7;
    	case 'R': return 13;
    	case 'U': return 14;
    	case 'D': return 11;
    	}
    	return -1;
    }
    
    
   
    
    
    
    
    
    static final Random random=new Random();
    
    static <T> void shuffle(T[] arr) {
    	int n = arr.length;
    	for(int i=0;i<n;i++	) {
    		int k = random.nextInt(n);
    		T temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;
    	}
    }
    
    	
    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
    
    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
   
  
    
    static void reverse(int[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    static void reverse(long[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    
    static <T> void reverse(T[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++) {
    		T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    	
    	
    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
     
    	public String next(){
    		while(!st.hasMoreElements()){
    			try{
    				st = new StringTokenizer(br.readLine());
    			} catch(IOException e){
    				e.printStackTrace();
    			}
    		}
    		return st.nextToken();
    	}
    		
    	public String nextLine() throws IOException {
    		return br.readLine();
    	}
    		
    	public int nextInt(){
    		return Integer.parseInt(next());
    	}
     
    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}
    		
    	public long nextLong() {
    		return Long.parseLong(next());
    	}
    		
    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }
   	
}