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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
 import java.util.*;
import java.util.InputMismatchException;
 
public class cf_355_{
static long big=1000000007;

static int chec(int k)
{
    if(k>3) return k-4; else return k;
}
static int min(int a,int b)
{if(a<b) return a; else return b;}
public static void main(String args[]) {
InputReader in = new InputReader(System.in);
      int n,m,i,j,k;n=in.readInt();m=in.readInt();
     boolean a[][][]=new boolean[n][m][4];
     for(i=0;i<n;i++) for(j=0;j<m;j++) for(k=0;k<4;k++) a[i][j][k]=true;
     for(i=0;i<n;i++)
     {
         char c[]=in.readString().toCharArray();
         for(j=0;j<m;j++)
         {
             if(c[j]=='*')
             {
                 a[i][j][0]=false;a[i][j][1]=false;a[i][j][2]=false;a[i][j][3]=false;
             }
             else if(c[j]=='-')
             {
                a[i][j][0]=false;a[i][j][2]=false;
             }
             else if(c[j]=='|')
               {
                 a[i][j][1]=false;a[i][j][3]=false;
             }
              else if(c[j]=='L')
               {
                 a[i][j][3]=false;
             }
              else if(c[j]=='R')
               {
                 a[i][j][1]=false;
             }
              else if(c[j]=='U')
               {
                 a[i][j][2]=false;}
              else if(c[j]=='D')
               {
                 a[i][j][0]=false;
             }
              else if(c[j]=='v')
               {
                  a[i][j][1]=false;a[i][j][2]=false;a[i][j][3]=false;
             }
              else if(c[j]=='^')
               {
                  a[i][j][0]=false;a[i][j][1]=false;a[i][j][3]=false;
             }
              else if(c[j]=='>')
               {
                 a[i][j][0]=false;a[i][j][2]=false;a[i][j][3]=false;
             }
              else if(c[j]=='<')
               {
                  a[i][j][0]=false;a[i][j][1]=false;a[i][j][2]=false;
             }

         }}
         int fin[][][]=new int[n][m][4];
         for(i=0;i<n;i++) for(j=0;j<m;j++) for(k=0;k<4;k++) fin[i][j][k]=10000000;
         int sx,sy,ex,ey;
         sx=in.readInt();sy=in.readInt();ex=in.readInt();ey=in.readInt();sx--;sy--;ex--;ey--;
         fin[sx][sy][0]=0;

         Queue<Integer> x = new LinkedList<Integer>();
Queue<Integer> y = new LinkedList<Integer>();
Queue<Integer> z = new LinkedList<Integer>();

         k=0;x.add(sx);y.add(sy);z.add(0);
         while(!x.isEmpty())
         {
             int xx=x.remove();//x.pop();
             int yy=y.remove();//y.pop();
             int kk=z.remove();//z.pop();
int bot=chec(0+kk);int top=chec(2+kk);int right=chec(1+kk); int left=chec(3+kk);
             if(xx+1<n && a[xx][yy][bot] && a[xx+1][yy][(top)] && fin[xx+1][yy][kk]==10000000 )
             {
                 fin[xx+1][yy][kk]=fin[xx][yy][kk]+1;
                 x.add(xx+1);y.add(yy);z.add(kk);if(xx+1==ex && yy==ey) break;
             }
             if(fin[xx][yy][right]==10000000)
               {

                fin[xx][yy][right]=fin[xx][yy][kk]+1;x.add(xx);y.add(yy);z.add(chec(kk+1));}
if(yy+1<m && a[xx][yy][right] && a[xx][yy+1][left] && fin[xx][yy+1][kk]==10000000 )
             {
                 fin[xx][yy+1][kk]=fin[xx][yy][kk]+1;
                 x.add(xx);y.add(yy+1);z.add(kk);if(xx==ex && yy+1==ey) break;
             }
             if(yy-1>=0 && a[xx][yy][left] && a[xx][yy-1][right] && fin[xx][yy-1][kk]==10000000 )
             {
                 fin[xx][yy-1][kk]=fin[xx][yy][kk]+1;
                 x.add(xx);y.add(yy-1);z.add(kk);if(xx==ex && yy-1==ey) break;
             }
             if(xx-1>=0 && a[xx][yy][top] && a[xx-1][yy][bot] && fin[xx-1][yy][kk]==10000000 )
             {
                 fin[xx-1][yy][kk]=fin[xx][yy][kk]+1;
                 x.add(xx-1);y.add(yy);z.add(kk);if(xx-1==ex && yy==ey) break;
             }
         }
         int ans=min(fin[ex][ey][0],min(fin[ex][ey][1],min(fin[ex][ey][2],fin[ex][ey][3])));
         if(ans!=10000000) System.out.println(ans); else System.out.println(-1);;
     }

}

class InputReader {
 
private InputStream stream;
 
private byte[] buf = new byte[1024];
 
private int curChar;
 
private int numChars;
 
private SpaceCharFilter filter;
 
public InputReader(InputStream stream) {
 
this.stream = stream;
 
}
 
public int read() {
 
if (numChars == -1) {
throw new InputMismatchException();
}
 
if (curChar >= numChars) {
 
curChar = 0;
 
try {
 
numChars = stream.read(buf);
 
} catch (IOException e) {
 
throw new InputMismatchException();
 
}
 
if (numChars <= 0) {
return -1;
}
 
}
return buf[curChar++];
 
}
 
public int readInt() {
 
int c = read();
 
while (isSpaceChar(c)) {
c = read();
}
 
int sgn = 1;
 
if (c == '-') {
 
sgn = -1;
 
c = read();
 
}
 
int res = 0;
 
do {
 
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
 
res *= 10;
res += c - '0';
 
c = read();
 
} while (!isSpaceChar(c));
 
return res * sgn;
 
}
 
public String readString() {
 
int c = read();
 
while (isSpaceChar(c)) {
c = read();
}
 
StringBuilder res = new StringBuilder();
 
do {
 
res.appendCodePoint(c);
 
c = read();
 
} while (!isSpaceChar(c));
 
return res.toString();
 
}
 
public double readDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
 
public long readLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public boolean isSpaceChar(int c) {
 
if (filter != null) {
return filter.isSpaceChar(c);
}
 
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
 
}
 
public String next() {
 
return readString();
}
 
public interface SpaceCharFilter {
 
public boolean isSpaceChar(int ch);
 
}
 
}
 
class OutputWriter {
 
private final PrintWriter writer;
 
public OutputWriter(OutputStream outputStream) {
 
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
 
}
 
public OutputWriter(Writer writer) {
 
this.writer = new PrintWriter(writer);
 
}
 
public void print(Object... objects) {
 
for (int i = 0; i < objects.length; i++) {
 
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
 
}
 
}
 
public void printLine(Object... objects) {
 
print(objects);
 
writer.println();
 
}
 
public void close() {
 
writer.close();
 
}
 
public void flush() {
 
writer.flush();
 
}
 
}