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.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;


public class Main {
	public static Map<Character,String> rotate = new HashMap<Character,String>();
	public static void initializeMap(){
		rotate.put('<',"<^>v");
		rotate.put('>',">v<^");
		rotate.put('^',"^>v<");
		rotate.put('v',"v<^>");
		rotate.put('R',"RDLU");
		rotate.put('L',"LURD");
		rotate.put('U',"URDL");
		rotate.put('D',"DLUR");
		rotate.put('+',"++++");
		rotate.put('-',"-|-|");
		rotate.put('|',"|-|-");
		rotate.put('*',"****");
	}
	public static boolean hasRight(char c){
		return c == '+' || c == '-' || c == '>' || c == 'L' || c == 'U' || c == 'D';
	}
	public static boolean hasLeft(char c){
		return c == '+' || c == '-' || c == '<' || c == 'R' || c == 'U' || c == 'D';
	}
	public static boolean hasUp(char c){
		return c == '+' || c == '|' || c == '^' || c == 'R' || c == 'L' || c == 'D';
	}
	public static boolean hasDown(char c){
		return c == '+' || c == '|' || c == 'v' || c == 'R' || c == 'U' || c == 'L';
	}
	public static boolean canGo(int fromX, int toX, int fromY, int toY, String[] matrix,int r){
		char from = rotate.get(matrix[fromX].charAt(fromY)).charAt(r);
		char to = rotate.get(matrix[toX].charAt(toY)).charAt(r);
		if(fromX == toX){
			if(toY < fromY){
				return hasRight(to) && hasLeft(from);
			}
			else{
				return hasLeft(to) && hasRight(from);
			}
		}
		else{
			if(toX < fromX){
				return hasDown(to) && hasUp(from);
			}
			else{
				return hasUp(to) && hasDown(from);
			}
		}
	}
	public static int bfs(String matrix[], int sourceX,int sourceY, int destX,int destY){
		ArrayList<Integer> xQueue = new ArrayList<Integer>();
		ArrayList<Integer> yQueue = new ArrayList<Integer>();
		ArrayList<Integer> lQueue = new ArrayList<Integer>();
		ArrayList<Integer> rQueue = new ArrayList<Integer>();	
		boolean[][][] visited = new boolean[4][matrix.length][matrix[0].length()];
		int start = 0;
		xQueue.add(sourceX);
		yQueue.add(sourceY);
		lQueue.add(0);
		rQueue.add(0);
		visited[0][sourceX][sourceY] = true;
		while(start < xQueue.size()){
			sourceX = xQueue.get(start);
			sourceY = yQueue.get(start);
			int sourceL = lQueue.get(start);
			int sourceR = rQueue.get(start);
			start++;
			if(sourceX == destX && sourceY == destY){
				return sourceL;
			}
			if(sourceX - 1 != -1){
				if(!visited[sourceR][sourceX - 1][sourceY]){
					if(canGo(sourceX,sourceX - 1,sourceY,sourceY,matrix,sourceR)){
						visited[sourceR][sourceX - 1][sourceY] = true;
						xQueue.add(sourceX - 1);
						yQueue.add(sourceY);
						lQueue.add(sourceL + 1);
						rQueue.add(sourceR);
					}
				}
			}
			if(sourceX + 1 != matrix.length){
				if(!visited[sourceR][sourceX + 1][sourceY]){
					if(canGo(sourceX,sourceX + 1,sourceY,sourceY,matrix,sourceR)){
						visited[sourceR][sourceX + 1][sourceY] = true;
						xQueue.add(sourceX + 1);
						yQueue.add(sourceY);
						lQueue.add(sourceL + 1);
						rQueue.add(sourceR);
					}
				}
			}
			if(sourceY - 1 != -1){
				if(!visited[sourceR][sourceX][sourceY - 1]){
					if(canGo(sourceX,sourceX,sourceY,sourceY - 1,matrix,sourceR)){
						visited[sourceR][sourceX][sourceY - 1] = true;
						xQueue.add(sourceX);
						yQueue.add(sourceY - 1);
						lQueue.add(sourceL + 1);
						rQueue.add(sourceR);
					}
				}
			}
			if(sourceY + 1 != matrix[0].length()){
				if(!visited[sourceR][sourceX][sourceY + 1]){
					if(canGo(sourceX,sourceX,sourceY,sourceY + 1,matrix,sourceR)){
						visited[sourceR][sourceX][sourceY + 1] = true;
						xQueue.add(sourceX);
						yQueue.add(sourceY + 1);
						lQueue.add(sourceL + 1);
						rQueue.add(sourceR);
					}
				}
			}
			if(!visited[(sourceR + 1) % 4][sourceX][sourceY]){
					visited[(sourceR + 1) % 4][sourceX][sourceY] = true;
					xQueue.add(sourceX);
					yQueue.add(sourceY);
					lQueue.add(sourceL + 1);
					rQueue.add((sourceR + 1) % 4);
			}
		}
		return -1;
	}
	public static void main(String[] args){
		InputReader sc = new InputReader(System.in);
		initializeMap();
		int n = sc.nextInt();
		int m = sc.nextInt();
		String[] matrix = new String[n];
		for(int i=0;i<n;i++){
			matrix[i] = sc.next();
		}
		int srcX = sc.nextInt() - 1;
		int srcY = sc.nextInt() - 1;
		int destX = sc.nextInt() - 1;
		int destY = sc.nextInt() - 1;
		System.out.println(bfs(matrix, srcX, srcY, destX, destY));
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			String str = "";
			try {
				str = reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}

			return str;
		}
	}
}