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.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	char[][] dir = { { '-', '|' }, { '^', '>', 'v', '<' }, { 'L', 'U', 'R', 'D' } };

	@SuppressWarnings("serial")
	Map<Character, Integer> map = new HashMap<Character, Integer>() {
		{ put('*', Integer.valueOf("0000", 2)); }
		{ put('+', Integer.valueOf("1111", 2)); }
		{ put('-', Integer.valueOf("0101", 2)); }
		{ put('|', Integer.valueOf("1010", 2)); }
		{ put('^', Integer.valueOf("0010", 2)); }
		{ put('>', Integer.valueOf("0001", 2)); }
		{ put('v', Integer.valueOf("1000", 2)); }
		{ put('<', Integer.valueOf("0100", 2)); }
		{ put('L', Integer.valueOf("1011", 2)); }
		{ put('U', Integer.valueOf("1101", 2)); }
		{ put('R', Integer.valueOf("1110", 2)); }
		{ put('D', Integer.valueOf("0111", 2)); }
	};

	void run() {
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] f = new char[h][w];
		for(int i = 0; i < h; i++) f[i] = sc.next().toCharArray();
		int[][][] c = new int[h][w][4];
		for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) Arrays.fill(c[i][j], Integer.MAX_VALUE / 10);
		int th = sc.nextInt() - 1;
		int tw = sc.nextInt() - 1;
		int mh = sc.nextInt() - 1;
		int mw = sc.nextInt() - 1;
		c[th][tw][0] = 0;
		Queue<Integer> que = new LinkedList<>();
		que.add(th);
		que.add(tw);
		que.add(0);
		int res = Integer.MAX_VALUE / 10;
		while (!que.isEmpty()) {
			int size = que.size();
			for (int i = 0; i < size / 3; i++) {
				int nh = que.poll();
				int nw = que.poll();
				int deg = que.poll();
				if (nh == mh && nw == mw) {
					res = Math.min(res, c[nh][nw][deg]);
					continue;
				}

				// up
				if (inner(nh - 1, nw, h, w)) {
					if (!(f[nh][nw] == '*' || f[nh - 1][nw] == '*')) {
						boolean from = false;
						boolean to = false;
						if (f[nh][nw] == '+')     from = true;
						if (f[nh - 1][nw] == '+') to = true;
						if (!from && (getDirection(f[nh][nw], deg) & 1 << 1) > 0)   from |= true;
						if (!to && (getDirection(f[nh - 1][nw], deg) & 1 << 3) > 0) to |= true;
						if (from && to && c[nh - 1][nw][deg] > c[nh][nw][deg] + 1) {
							c[nh - 1][nw][deg] = c[nh][nw][deg] + 1;
							que.add(nh - 1);
							que.add(nw);
							que.add(deg);
						}
					}
				}
				// right
				if (inner(nh, nw + 1, h, w)) {
					if (!(f[nh][nw] == '*' || f[nh][nw + 1] == '*')) {
						boolean from = false;
						boolean to = false;
						if (f[nh][nw] == '+')     from = true;
						if (f[nh][nw + 1] == '+') to = true;
						if (!from && (getDirection(f[nh][nw], deg) & 1 << 0) > 0)   from |= true;
						if (!to && (getDirection(f[nh][nw + 1], deg) & 1 << 2) > 0) to |= true;
						if (from && to && c[nh][nw + 1][deg] > c[nh][nw][deg] + 1) {
							c[nh][nw + 1][deg] = c[nh][nw][deg] + 1;
							que.add(nh);
							que.add(nw + 1);
							que.add(deg);
						}
					}
				}
				// left
				if (inner(nh, nw - 1, h, w)) {
					if (!(f[nh][nw] == '*' || f[nh][nw - 1] == '*')) {
						boolean from = false;
						boolean to = false;
						if (f[nh][nw] == '+')     from = true;
						if (f[nh][nw - 1] == '+') to = true;
						if (!from && (getDirection(f[nh][nw], deg) & 1 << 2) > 0)   from |= true;
						if (!to && (getDirection(f[nh][nw - 1], deg) & 1 << 0) > 0) to |= true;
						if (from && to && c[nh][nw - 1][deg] > c[nh][nw][deg] + 1) {
							c[nh][nw - 1][deg] = c[nh][nw][deg] + 1;
							que.add(nh);
							que.add(nw - 1);
							que.add(deg);
						}
					}
				}
				// down
				if (inner(nh + 1, nw, h, w)) {
					if (!(f[nh][nw] == '*' || f[nh + 1][nw] == '*')) {
						boolean from = false;
						boolean to = false;
						if (f[nh][nw] == '+')     from = true;
						if (f[nh + 1][nw] == '+') to = true;
						if (!from && (getDirection(f[nh][nw], deg) & 1 << 3) > 0)   from |= true;
						if (!to && (getDirection(f[nh + 1][nw], deg) & 1 << 1) > 0) to |= true;
						if (from && to && c[nh + 1][nw][deg] > c[nh][nw][deg] + 1) {
							c[nh + 1][nw][deg] = c[nh][nw][deg] + 1;
							que.add(nh + 1);
							que.add(nw);
							que.add(deg);
						}
					}
				}
				// rotate
				if (c[nh][nw][(deg + 1) % 4] > c[nh][nw][deg] + 1) {
					c[nh][nw][(deg + 1) % 4] = c[nh][nw][deg] + 1;
					que.add(nh);
					que.add(nw);
					que.add((deg + 1) % 4);
				}
			}
		}
		System.out.println(res == Integer.MAX_VALUE / 10 ? -1 : res);
	}

	int getDirection(char d, int rotate) {
		for (int i = 0; i < dir.length; i++) {
			for (int j = 0; j < dir[i].length; j++) {
				if (dir[i][j] == d) return map.get(dir[i][(j + rotate) % dir[i].length]);
			}
		}
		return -1;
	}

	public static void main(String[] args) {
		new Main().run();
	}

	boolean inner(int h, int w, int limH, int limW) {
		return 0 <= h && h < limH && 0 <= w && w < limW;
	}
}