#include <bits/stdc++.h>
using namespace std;
struct state {
  int x;
  int y;
  int ori;
};
string rot(string s, int a) {
  string ans = "0000";
  for (int i = 0; i < 4; i++) {
    ans[(i + a) % 4] = s[i];
  }
  return ans;
}
int main() {
  map<char, string> m1;
  m1['+'] = "1111";
  m1['-'] = "0101";
  m1['|'] = "1010";
  m1['^'] = "1000";
  m1['>'] = "0100";
  m1['v'] = "0010";
  m1['<'] = "0001";
  m1['L'] = "1110";
  m1['R'] = "1011";
  m1['U'] = "0111";
  m1['D'] = "1101";
  m1['*'] = "0000";
  int n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int xt, yt;
  cin >> xt >> yt;
  int xm, ym;
  cin >> xm >> ym;
  xt--;
  yt--;
  xm--;
  ym--;
  queue<state> q;
  state temp;
  temp.x = xt;
  temp.y = yt;
  temp.ori = 0;
  q.push(temp);
  int vis[n][m][4];
  memset(vis, 0, sizeof(vis));
  int dist[n][m][4];
  memset(dist, -1, sizeof(dist));
  int xr[4] = {-1, 0, 1, 0};
  int yr[4] = {0, 1, 0, -1};
  vis[xt][yt][0] = 1;
  dist[xt][yt][0] = 0;
  while (!q.empty()) {
    state cur = q.front();
    q.pop();
    string s1 = rot(m1[s[cur.x][cur.y]], cur.ori);
    for (int i = 0; i < 4; i++) {
      if (s1[i] == '1') {
        int x1, y1;
        x1 = cur.x + xr[i];
        y1 = cur.y + yr[i];
        if (x1 >= 0 && x1 < n && y1 >= 0 && y1 < m && !vis[x1][y1][cur.ori]) {
          string s2 = rot(m1[s[x1][y1]], cur.ori);
          if (s2[(i + 2) % 4] == '0') continue;
          vis[x1][y1][cur.ori] = 1;
          dist[x1][y1][cur.ori] = dist[cur.x][cur.y][cur.ori] + 1;
          state t1;
          t1.x = x1;
          t1.y = y1;
          t1.ori = cur.ori;
          q.push(t1);
        }
      }
    }
    if (!vis[cur.x][cur.y][(cur.ori + 1) % 4]) {
      vis[cur.x][cur.y][(cur.ori + 1) % 4] = 1;
      dist[cur.x][cur.y][(cur.ori + 1) % 4] = dist[cur.x][cur.y][cur.ori] + 1;
      state t1;
      t1.x = cur.x;
      t1.y = cur.y;
      t1.ori = (cur.ori + 1) % 4;
      q.push(t1);
    }
  }
  int minn = INT_MAX;
  for (int i = 0; i < 4; i++) {
    minn = min(minn, dist[xm][ym][i]);
  }
  cout << minn << "\n";
}
