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.util.*;

public class Timus1177 implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Throwable e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) {
        new Thread(null, new Timus1177(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    char rotate(char x) {
        switch (x) {
            case '+':
                return '+';
            case '-':
                return '|';
            case '|':
                return '-';
            case '^':
                return '>';
            case '>':
                return 'v';
            case 'v':
                return '<';
            case '<':
                return '^';
            case 'L':
                return 'U';
            case 'U':
                return 'R';
            case 'R':
                return 'D';
            case 'D':
                return 'L';
            case '*':
                return '*';
        }
        throw new RuntimeException();
    }

    int[] di = {0, 0, 1, -1};
    int[] dj = {-1, 1, 0, 0};
    int[] first = {0, 1, 2, 3};
    int[] second = {1, 0, 3, 2};


    char[] hasLeft =  "+-<URD".toCharArray();//0
    char[] hasRight = "+->ULD".toCharArray();//1
    char[] hasDown =  "+|vLRU".toCharArray();//2
    char[] hasUp =    "+|^LRD".toCharArray();//3

    boolean has(char[] a, char x) {
        for (int y : a) {
            if (y == x) return true;
        }
        return false;
    }

    class State {
        int dir;
        int x;
        int y;

        public State(int dir, int x, int y) {
            this.dir = dir;
            this.x = x;
            this.y = y;
        }
    }

    void solve() throws IOException {
        int n = readInt();
        int m = readInt();

        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) {
            map[i] = readString().toCharArray();
        }

        char[][] directions = new char[4][];
        directions[0] = hasLeft;
        directions[1] = hasRight;
        directions[2] = hasDown;
        directions[3] = hasUp;

        char[][] pos = new char[256][4];
        char[] types = "+-|^><vLURD*".toCharArray();
        for (char x : types) {
            char y = x;
            for (int i = 0; i < 4; i++) {
                pos[x][i] = y;
                y = rotate(y);
            }
        }

        int[][][] dist = new int[4][n][m];
        for (int[][] v : dist) {
            for (int[] b : v) {
                Arrays.fill(b, Integer.MAX_VALUE);
            }
        }

        int fx = readInt() - 1;
        int fy = readInt() - 1;
        dist[0][fx][fy] = 0;

        ArrayDeque<State> deq = new ArrayDeque<>();
        deq.add(new State(0, fx, fy));

        while (!deq.isEmpty()) {
            State state = deq.poll();
            int d = dist[state.dir][state.x][state.y];

            if (dist[(state.dir + 1) % 4][state.x][state.y] == Integer.MAX_VALUE) {
                dist[(state.dir + 1) % 4][state.x][state.y] = d + 1;
                deq.add(new State((state.dir + 1) % 4, state.x, state.y));
            }

            int x = state.x;
            int y = state.y;
            int direct = state.dir;

            for (int dir = 0; dir < 4; dir++) {
                int nx = state.x + di[dir];
                int ny = state.y + dj[dir];

                if (nx >= 0 && ny >= 0 && nx < n && ny < m && dist[direct][nx][ny] == Integer.MAX_VALUE) {
                    char a = pos[map[x][y]][direct];
                    char b = pos[map[nx][ny]][direct];

                    if (!has(directions[first[dir]], a) || !has(directions[second[dir]], b)) continue;
                    dist[direct][nx][ny] = d + 1;
                    deq.add(new State(direct, nx, ny));
                }
            }
        }

        int min = Integer.MAX_VALUE;
        int tox = readInt() - 1;
        int toy = readInt() - 1;
        for (int i = 0; i < 4; i++) {
            min = Math.min(min, dist[i][tox][toy]);
        }
        if (Integer.MAX_VALUE == min) {
            out.println(-1);
        } else {
            out.println(min);
        }

    }


    static final class LongIntHashMap {
        final static class Entry {
            final long key;
            int value;
            Entry next;

            Entry(long key, int value, Entry next) {
                this.key = key;
                this.value = value;
                this.next = next;
            }
        }

        private Entry[] table;
        private int capacity;
        private int threshold;
        private int size;

        public LongIntHashMap() {
            this(16);
        }

        @SuppressWarnings("unchecked")
        public LongIntHashMap(int capacity) {
            this.capacity = capacity;
            this.threshold = capacity * 4 / 3;
            this.table = new Entry[capacity];
        }

        public boolean containsKey(long key) {
            final int index = ((((int) (key >>> 32)) ^ ((int) (key))) & 0x7fffffff) % capacity;

            for (Entry entry = table[index]; entry != null; entry = entry.next) {
                if (entry.key == key) {
                    return true;
                }
            }
            return false;
        }

        public int get(long key) {
            final int index = ((((int) (key >>> 32)) ^ ((int) (key))) & 0x7fffffff) % capacity;
            for (Entry entry = table[index]; entry != null; entry = entry.next) {
                if (entry.key == key) {
                    return entry.value;
                }
            }
            return 0;
        }

        public int put(long key, int value) {
            final int index = ((((int) (key >>> 32)) ^ ((int) (key))) & 0x7fffffff) % capacity;
            final Entry entryOriginal = table[index];
            for (Entry entry = entryOriginal; entry != null; entry = entry.next) {
                if (entry.key == key) {
                    int oldValue = entry.value;
                    entry.value = value;
                    return oldValue;
                }
            }
            table[index] = new Entry(key, value, entryOriginal);
            size++;
            if (size > threshold) {
                setCapacity(2 * capacity);
            }
            return 0;
        }

        public int remove(long key) {
            int index = ((((int) (key >>> 32)) ^ ((int) (key))) & 0x7fffffff) % capacity;
            Entry previous = null;
            Entry entry = table[index];
            while (entry != null) {
                Entry next = entry.next;
                if (entry.key == key) {
                    if (previous == null) {
                        table[index] = next;
                    } else {
                        previous.next = next;
                    }
                    size--;
                    return entry.value;
                }
                previous = entry;
                entry = next;
            }
            return 0;
        }

        public void clear() {
            size = 0;
            Arrays.fill(table, null);
        }

        public int size() {
            return size;
        }

        public void setCapacity(int newCapacity) {
            @SuppressWarnings("unchecked")
            Entry[] newTable = new Entry[newCapacity];
            int length = table.length;
            for (int i = 0; i < length; i++) {
                Entry entry = table[i];
                while (entry != null) {
                    long key = entry.key;
                    int index = ((((int) (key >>> 32)) ^ ((int) (key))) & 0x7fffffff) % newCapacity;

                    Entry originalNext = entry.next;
                    entry.next = newTable[index];
                    newTable[index] = entry;
                    entry = originalNext;
                }
            }
            table = newTable;
            capacity = newCapacity;
            threshold = newCapacity * 4 / 3;
        }

        /**
         * Target load: 0,6
         */
        public void reserveRoom(int entryCount) {
            setCapacity(entryCount * 5 / 3);
        }

    }

}