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.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.interfaces.DSAKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class a {

	public static class in {
		static BufferedReader reader;
		static StringTokenizer tokenizer;

		static void init(InputStream input) throws FileNotFoundException {
			// reader = new BufferedReader(new
			// FileReader("B-small-attempt4.in"));
			reader = new BufferedReader(new InputStreamReader(input));
			tokenizer = new StringTokenizer("");
		}

		static String next() throws IOException {
			while (!tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(reader.readLine());
			return tokenizer.nextToken();
		}

		static int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		static double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		static long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}

	public static long comp(int n, int r) {
		r = Math.min(r, n - r);
		long ans = 1;
		for (int i = 1; i <= r; i++) {
			ans = ans * (long) (n - r + i) / (long) i;
		}
		return ans;

	}

	public static class node {

		int x;
		int y;
		int p;

		node(int x, int y, int p) {
			this.x = x;
			this.y = y;
			this.p = p;

		}

	}

	public static long gcd(int x, int y) {
		if (y == 0)
			return x;
		return gcd(y, x % y);
	}

	public static int tree[];

	public static void add(int idx, long val, int n, int tree[]) {

		while (idx <= n) {
			tree[idx] += val;
			idx += (idx & -idx);
		}
	}

	public static int get(int idx) {
		int g = 0;
		while (idx > 0) {

			g += tree[idx];
			idx -= (idx & -idx);
		}

		return g;
	}

	public static class point implements Comparable<point> {
		int min;
		int a;
		int b;

		point(int min, int a, int b) {
			this.min = min;
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(point o) {
			if (o.min > min)
				return 1;
			else if (o.min < min)
				return -1;
			return 0;
		}
	}

	// for bad input
	static String ReadLn(int maxLg) {
		byte lin[] = new byte[maxLg];
		int lg = 0, car = -1;
		String line = "";

		try {
			while (lg < maxLg) {
				car = System.in.read();
				if ((car < 0) || (car == '\n'))
					break;
				lin[lg++] += car;
			}
		} catch (IOException e) {
			return (null);
		}

		if ((car < 0) && (lg == 0))
			return (null);
		return (new String(lin, 0, lg));
	}

	// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM
	// SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED
	// DEFINE ANY CLASS AND METHOD NEEDED
	// LNode CLASS IS DEFINED BY DEFAULT
	// CLASS BEGINS, THIS CLASS IS REQUIRED

	public class LNode {
		public int value;
		public LNode next;

	}

	public static class ReverseLinkedList {
		// METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIRED
		public static LNode reverseLinkedList(LNode list) {
			// INSERT YOUR CODE HERE
			int n = 0;
			LNode pointer = list;
			while (pointer != null) {
				n++;
				pointer = pointer.next;
			}

			int mid = (n + 1) / 2;
			if (n % 2 == 1)
				mid--;
			LNode arr[] = new LNode[n - mid];
			pointer = list;
			int p = 0;
			int c = 0;
			while (pointer != null) {

				if (c >= mid) {
					arr[p++] = pointer;
				}
				c++;
				pointer = pointer.next;
			}
			LNode swap = null;
			for (int i = 0; i < (n - mid) / 2; i++) {
				swap = arr[i];
				arr[i] = arr[n - mid - 1 - i];
				arr[n - mid - 1 - i] = swap;
			}

			pointer = list;
			p = 0;
			c = 0;
			while (pointer != null) {

				if (c >= mid - 1) {
					pointer.next = arr[p++];
				}
				c++;
				pointer = pointer.next;
			}

			return list;
		}
		// METHOD SIGNATURE ENDS
	}

	public static class points implements Comparable<points> {

		int dur;
		int idx;

		points(int d, int i) {
			dur = d;
			idx = i;
		}

		@Override
		public int compareTo(points o) {
			if (o.dur < dur)
				return 1;
			else if (o.dur > dur)
				return -1;
			else if (o.idx < idx)
				return 1;
			else
				return -1;

		}
	}

	public static int dx[] = { 1, 0, 0, -1 };
	public static int dy[] = { 0, 1, -1, 0 };
	public static char[][][] arr;
	public static boolean[][][] vis;
	public static int dp[][][];
	public static int n;
	public static int m;
	public static HashSet<Character>[] set;

	public static boolean check(int x, int y, int p) {
		if (x >= 0 && y >= 0 && x < n && y < m && !vis[x][y][p])
			return true;

		return false;
	}

	public static int solve(node st, node end) {
		Queue<node> q = new LinkedList();
		q.add(st);
		vis[st.x][st.y][st.p] = true;
		dp[st.x][st.y][st.p] = 0;
		while (!q.isEmpty()) {

			node e = q.poll();
			int x = e.x;
			int y = e.y;
			//System.out.println(x+" "+y+" "+e.p+" "+arr[x][y][e.p]+" "+dp[x][y][e.p]);
			
			if (x == end.x && y == end.y)
				return dp[x][y][e.p];

			int new_p = (e.p + 1) % 4;
			if (!vis[x][y][new_p]) {
				dp[x][y][new_p] = dp[x][y][e.p] + 1;
				vis[x][y][new_p] = true;
				q.add(new node(x, y, new_p));
			}

			if (arr[x][y][e.p] == '+') {
				for (int i = 0; i < 4; i++) {
					int x1 = x + dx[i];
					int y1 = y + dy[i];
					if (check(x1, y1, e.p) && set[i].contains(arr[x1][y1][e.p])) {
						vis[x1][y1][e.p] = true;
						dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
						q.add(new node(x1, y1, e.p));
					}
				}
			} else if (arr[x][y][e.p] == '-') {
				for (int i = 1; i < 3; i++) {
					int x1 = x + dx[i];
					int y1 = y + dy[i];
					if (check(x1, y1, e.p) && set[i].contains(arr[x1][y1][e.p])) {
						vis[x1][y1][e.p] = true;
						dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
						q.add(new node(x1, y1, e.p));
					}
				}
			} else if (arr[x][y][e.p] == '|') {
				for (int i = 0; i < 4; i++) {
					if (i == 1 || i == 2)
						continue;
					int x1 = x + dx[i];
					int y1 = y + dy[i];
					if (check(x1, y1, e.p) && set[i].contains(arr[x1][y1][e.p])) {
						vis[x1][y1][e.p] = true;
						dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
						q.add(new node(x1, y1, e.p));
					}
				}
			} else if (arr[x][y][e.p] == '^') {
				int x1 = x + dx[3];
				int y1 = y + dy[3];
				if (check(x1, y1, e.p) && set[3].contains(arr[x1][y1][e.p])) {
					vis[x1][y1][e.p] = true;
					dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
					q.add(new node(x1, y1, e.p));
				}
			} else if (arr[x][y][e.p] == '>') {
				int x1 = x + dx[1];
				int y1 = y + dy[1];
				if (check(x1, y1, e.p) && set[1].contains(arr[x1][y1][e.p])) {
					vis[x1][y1][e.p] = true;
					dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
					q.add(new node(x1, y1, e.p));
				}
			} else if (arr[x][y][e.p] == 'v') {
				int x1 = x + dx[0];
				int y1 = y + dy[0];
				if (check(x1, y1, e.p) && set[0].contains(arr[x1][y1][e.p])) {
					vis[x1][y1][e.p] = true;
					dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
					q.add(new node(x1, y1, e.p));
				}
			} else if (arr[x][y][e.p] == '<') {
				int x1 = x + dx[2];
				int y1 = y + dy[2];
				if (check(x1, y1, e.p) && set[2].contains(arr[x1][y1][e.p])) {
					vis[x1][y1][e.p] = true;
					dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
					q.add(new node(x1, y1, e.p));
				}
			} else if (arr[x][y][e.p] == 'L') {
				for (int i = 0; i < 4; i++) {
					if (i == 2)
						continue;
					int x1 = x + dx[i];
					int y1 = y + dy[i];
					if (check(x1, y1, e.p) && set[i].contains(arr[x1][y1][e.p])) {
						vis[x1][y1][e.p] = true;
						dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
						q.add(new node(x1, y1, e.p));
					}
				}

			} else if (arr[x][y][e.p] == 'R') {
				for (int i = 0; i < 4; i++) {
					if (i == 1)
						continue;
					int x1 = x + dx[i];
					int y1 = y + dy[i];
					if (check(x1, y1, e.p) && set[i].contains(arr[x1][y1][e.p])) {
						vis[x1][y1][e.p] = true;
						dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
						q.add(new node(x1, y1, e.p));
					}
				}
			} else if (arr[x][y][e.p] == 'U') {
				for (int i = 0; i < 4; i++) {
					if (i == 3)
						continue;
					int x1 = x + dx[i];
					int y1 = y + dy[i];
					if (check(x1, y1, e.p) && set[i].contains(arr[x1][y1][e.p])) {
						vis[x1][y1][e.p] = true;
						dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
						q.add(new node(x1, y1, e.p));
					}
				}
			} else if (arr[x][y][e.p] == 'D') {
				for (int i = 0; i < 4; i++) {
					if (i == 0)
						continue;
					int x1 = x + dx[i];
					int y1 = y + dy[i];
					if (check(x1, y1, e.p) && set[i].contains(arr[x1][y1][e.p])) {
						vis[x1][y1][e.p] = true;
						dp[x1][y1][e.p] = dp[x][y][e.p] + 1;
						q.add(new node(x1, y1, e.p));
					}
				}
			}

		}
		return -1;
	}

	public static void main(String[] args) throws IOException {
		// StringBuilder qq = new StringBuilder();
		in.init(System.in);
		PrintWriter out = new PrintWriter(System.out);
		n = in.nextInt();
		m = in.nextInt();
		set = new HashSet[4];
		for (int i = 0; i < 4; i++) {
			set[i] = new HashSet();
		}
		set[0].add('+');
		set[0].add('^');
		set[0].add('|');
		set[0].add('L');
		set[0].add('R');
		set[0].add('D');
		// ...................................
		set[1].add('+');
		set[1].add('<');
		set[1].add('-');
		set[1].add('U');
		set[1].add('R');
		set[1].add('D');
		// -----------------------------------------
		set[2].add('+');
		set[2].add('>');
		set[2].add('-');
		set[2].add('L');
		set[2].add('U');
		set[2].add('D');
		// .......................................
		set[3].add('+');
		set[3].add('v');
		set[3].add('|');
		set[3].add('L');
		set[3].add('R');
		set[3].add('U');
		// ..................................
		arr = new char[n][m][4];
		vis = new boolean[n][m][4];
		dp = new int[n][m][4];
		for (int i = 0; i < n; i++) {
			String a = in.next();
			for (int j = 0; j < m; j++) {

				if (a.charAt(j) == '+') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = a.charAt(j);
					arr[i][j][2] = a.charAt(j);
					arr[i][j][3] = a.charAt(j);

				} else if (a.charAt(j) == '*') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = a.charAt(j);
					arr[i][j][2] = a.charAt(j);
					arr[i][j][3] = a.charAt(j);
				} else if (a.charAt(j) == '-') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = '|';
					arr[i][j][2] = a.charAt(j);
					arr[i][j][3] = '|';
				} else if (a.charAt(j) == '|') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = '-';
					arr[i][j][2] = a.charAt(j);
					arr[i][j][3] = '-';
				} else if (a.charAt(j) == '^') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = '>';
					arr[i][j][2] = 'v';
					arr[i][j][3] = '<';
				} else if (a.charAt(j) == '>') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = 'v';
					arr[i][j][2] = '<';
					arr[i][j][3] = '^';
				} else if (a.charAt(j) == '<') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = '^';
					arr[i][j][2] = '>';
					arr[i][j][3] = 'v';
				} else if (a.charAt(j) == 'v') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = '<';
					arr[i][j][2] = '^';
					arr[i][j][3] = '>';
				} else if (a.charAt(j) == 'L') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = 'U';
					arr[i][j][2] = 'R';
					arr[i][j][3] = 'D';
				} else if (a.charAt(j) == 'R') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = 'D';
					arr[i][j][2] = 'L';
					arr[i][j][3] = 'U';
				} else if (a.charAt(j) == 'U') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = 'R';
					arr[i][j][2] = 'D';
					arr[i][j][3] = 'L';
				} else if (a.charAt(j) == 'D') {
					arr[i][j][0] = a.charAt(j);
					arr[i][j][1] = 'L';
					arr[i][j][2] = 'U';
					arr[i][j][3] = 'R';
				}

			}
		}

		int stx = in.nextInt()-1;
		int endx = in.nextInt()-1;
		int sty = in.nextInt()-1;
		int endy = in.nextInt()-1;

		out.println(solve(new node(stx, endx, 0), new node(sty, endy, 0)));

		out.close();

	}
}