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.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P676D {

  void show(int [][][] l) {
    for (int k = 0; k < l.length; k++) {
      println("-----------------------------------------------------------");
      for (int i = 0; i < l[0].length; i++) {
        for (int j = 0; j < l[0][0].length; j++) {
          print(Integer.toString(l[k][i][j], 16) + ",");
        }
        println();
      }
    }
    pw.flush();
  }

  final static int X = 1;
  final static int Y = 0;
  final static int [][] DYX = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
  final static int SHIFT = 2;
  final static int SMASK = 0b11;

  class YXZT {
    int x, y, z, t;

    public YXZT(int y, int x, int z, int t) {
      this.x = x;
      this.y = y;
      this.z = z;
      this.t = t;
    }

    public YXZT move(int dy, int dx, int dz) {
      return new YXZT(y + dy, x + dx, (z + dz) & SMASK, t + 1);
    }
  }

  public void run() throws Exception {
    int n = nextInt();
    int m = nextInt();

    Map<Character, Integer> conv = new HashMap(12);
    conv.put('+', 0b1111); conv.put('-', 0b0101); conv.put('|', 0b1010); conv.put('^', 0b1000);
    conv.put('>', 0b0100); conv.put('<', 0b0001); conv.put('v', 0b0010); conv.put('L', 0b1110);
    conv.put('R', 0b1011); conv.put('U', 0b0111); conv.put('D', 0b1101); conv.put('*', 0b0000);

    int [][][] l = new int [4][n][m];
    int [][][] t = new int [4][n][m];
    for (int k = 0; k < 4; k++) {
      for (int i = 0; i < n; i++) {
        String s = (k == 0) ? next() : null;
        for (int j = 0; j < m; j++) {
          l[k][i][j] = (k == 0) ? conv.get(s.charAt(j)) : ((l[k - 1][i][j] >>> 1) | ((l[k - 1][i][j] & 1) << 3));
          t[k][i][j] = Integer.MAX_VALUE;
        }
      }
    }

    int yt = nextInt() - 1;
    int xt = nextInt() - 1;
    int ym = nextInt() - 1;
    int xm = nextInt() - 1;
    t[0][yt][xt] = 0;
    Deque<YXZT> w = new ArrayDeque();
    w.addLast(new YXZT(yt, xt, 0, 0));

    while (w.size() > 0) {
      YXZT lyxzt = w.pollFirst();

      for (int i = 0; i < 4; i++) {
        YXZT yxzt = lyxzt.move(DYX[i][Y], DYX[i][X], 0);
        if ((yxzt.y >= 0) && (yxzt.y < n) && (yxzt.x >= 0) && (yxzt.x < m) &&
            (t[yxzt.z][yxzt.y][yxzt.x] > yxzt.t) &&
            ((l[lyxzt.z][lyxzt.y][lyxzt.x] & (1 << i)) != 0) &&
            ((l[yxzt.z][yxzt.y][yxzt.x] & (1 << ((i + SHIFT) & SMASK))) != 0)) {
            w.addLast(yxzt);
            t[yxzt.z][yxzt.y][yxzt.x] = yxzt.t;
        }
      }

      lyxzt = lyxzt.move(0, 0, 1);
      if (t[lyxzt.z][lyxzt.y][lyxzt.x] > lyxzt.t) {
        w.addLast(lyxzt);
        t[lyxzt.z][lyxzt.y][lyxzt.x] = lyxzt.t;
      }
    }

    int ans = Math.min(Math.min(t[0][ym][xm], t[1][ym][xm]), Math.min(t[2][ym][xm], t[3][ym][xm]));
    println((ans == Integer.MAX_VALUE) ? -1 : ans);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P676D().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    return ((b > 0) ? gcd(b, a % b) : a);
  }
}