#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int MAXN = 1000;
const int MAXD = 4;
const pair<int, int> U = make_pair(-1, 0);
const pair<int, int> D = make_pair(1, 0);
const pair<int, int> L = make_pair(0, -1);
const pair<int, int> R = make_pair(0, 1);
const int up = 0;
const int dn = 1;
const int lf = 2;
const int rg = 3;
struct State {
  int r, c, dir;
  State(int r, int c, int dir) : r(r), c(c), dir(dir){};
};
char g[MAXN][MAXN];
int dist[MAXN][MAXN][MAXD];
map<char, vector<pair<int, pair<int, int> > >[MAXD]> dir;
int n, m;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
}
void preprocess() {
  dir['|'][0].push_back(make_pair(up, U)),
      dir['|'][0].push_back(make_pair(dn, D));
  dir['|'][1].push_back(make_pair(lf, L)),
      dir['|'][1].push_back(make_pair(rg, R));
  dir['|'][2].push_back(make_pair(up, U)),
      dir['|'][2].push_back(make_pair(dn, D));
  dir['|'][3].push_back(make_pair(lf, L)),
      dir['|'][3].push_back(make_pair(rg, R));
  dir['-'][0].push_back(make_pair(lf, L)),
      dir['-'][0].push_back(make_pair(rg, R));
  dir['-'][1].push_back(make_pair(up, U)),
      dir['-'][1].push_back(make_pair(dn, D));
  dir['-'][2].push_back(make_pair(lf, L)),
      dir['-'][2].push_back(make_pair(rg, R));
  dir['-'][3].push_back(make_pair(up, U)),
      dir['-'][3].push_back(make_pair(dn, D));
  dir['^'][0].push_back(make_pair(up, U));
  dir['^'][1].push_back(make_pair(rg, R));
  dir['^'][2].push_back(make_pair(dn, D));
  dir['^'][3].push_back(make_pair(lf, L));
  dir['>'][0].push_back(make_pair(rg, R));
  dir['>'][1].push_back(make_pair(dn, D));
  dir['>'][2].push_back(make_pair(lf, L));
  dir['>'][3].push_back(make_pair(up, U));
  dir['<'][0].push_back(make_pair(lf, L));
  dir['<'][1].push_back(make_pair(up, U));
  dir['<'][2].push_back(make_pair(rg, R));
  dir['<'][3].push_back(make_pair(dn, D));
  dir['v'][0].push_back(make_pair(dn, D));
  dir['v'][1].push_back(make_pair(lf, L));
  dir['v'][2].push_back(make_pair(up, U));
  dir['v'][3].push_back(make_pair(rg, R));
  dir['L'][0].push_back(make_pair(dn, D)),
      dir['L'][0].push_back(make_pair(up, U)),
      dir['L'][0].push_back(make_pair(rg, R));
  dir['L'][1].push_back(make_pair(lf, L)),
      dir['L'][1].push_back(make_pair(rg, R)),
      dir['L'][1].push_back(make_pair(dn, D));
  dir['L'][2].push_back(make_pair(dn, D)),
      dir['L'][2].push_back(make_pair(lf, L)),
      dir['L'][2].push_back(make_pair(up, U));
  dir['L'][3].push_back(make_pair(lf, L)),
      dir['L'][3].push_back(make_pair(up, U)),
      dir['L'][3].push_back(make_pair(rg, R));
  dir['R'][0].push_back(make_pair(dn, D)),
      dir['R'][0].push_back(make_pair(lf, L)),
      dir['R'][0].push_back(make_pair(up, U));
  dir['R'][1].push_back(make_pair(lf, L)),
      dir['R'][1].push_back(make_pair(up, U)),
      dir['R'][1].push_back(make_pair(rg, R));
  dir['R'][2].push_back(make_pair(up, U)),
      dir['R'][2].push_back(make_pair(rg, R)),
      dir['R'][2].push_back(make_pair(dn, D));
  dir['R'][3].push_back(make_pair(dn, D)),
      dir['R'][3].push_back(make_pair(lf, L)),
      dir['R'][3].push_back(make_pair(rg, R));
  dir['U'][0].push_back(make_pair(dn, D)),
      dir['U'][0].push_back(make_pair(lf, L)),
      dir['U'][0].push_back(make_pair(rg, R));
  dir['U'][1].push_back(make_pair(dn, D)),
      dir['U'][1].push_back(make_pair(lf, L)),
      dir['U'][1].push_back(make_pair(up, U));
  dir['U'][2].push_back(make_pair(lf, L)),
      dir['U'][2].push_back(make_pair(up, U)),
      dir['U'][2].push_back(make_pair(rg, R));
  dir['U'][3].push_back(make_pair(dn, D)),
      dir['U'][3].push_back(make_pair(up, U)),
      dir['U'][3].push_back(make_pair(rg, R));
  dir['D'][0].push_back(make_pair(lf, L)),
      dir['D'][0].push_back(make_pair(up, U)),
      dir['D'][0].push_back(make_pair(rg, R));
  dir['D'][1].push_back(make_pair(dn, D)),
      dir['D'][1].push_back(make_pair(up, U)),
      dir['D'][1].push_back(make_pair(rg, R));
  dir['D'][2].push_back(make_pair(dn, D)),
      dir['D'][2].push_back(make_pair(lf, L)),
      dir['D'][2].push_back(make_pair(rg, R));
  dir['D'][3].push_back(make_pair(dn, D)),
      dir['D'][3].push_back(make_pair(lf, L)),
      dir['D'][3].push_back(make_pair(up, U));
  dir['+'][0].push_back(make_pair(lf, L)),
      dir['+'][0].push_back(make_pair(up, U)),
      dir['+'][0].push_back(make_pair(rg, R)),
      dir['+'][0].push_back(make_pair(dn, D));
  dir['+'][1].push_back(make_pair(lf, L)),
      dir['+'][1].push_back(make_pair(up, U)),
      dir['+'][1].push_back(make_pair(rg, R)),
      dir['+'][1].push_back(make_pair(dn, D));
  dir['+'][2].push_back(make_pair(lf, L)),
      dir['+'][2].push_back(make_pair(up, U)),
      dir['+'][2].push_back(make_pair(rg, R)),
      dir['+'][2].push_back(make_pair(dn, D));
  dir['+'][3].push_back(make_pair(lf, L)),
      dir['+'][3].push_back(make_pair(up, U)),
      dir['+'][3].push_back(make_pair(rg, R)),
      dir['+'][3].push_back(make_pair(dn, D));
}
bool ok(int nr, int nc) {
  bool can_r = nr >= 0 and nr < n;
  bool can_c = nc >= 0 and nc < m;
  return can_r and can_c and (g[nr][nc] != '*');
}
bool opposite(pair<int, pair<int, int> > o, char c, int i) {
  int op = -1;
  if (o.first == 0)
    op = 1;
  else if (o.first == 1)
    op = 0;
  else if (o.first == 2)
    op = 3;
  else if (o.first == 3)
    op = 2;
  for (auto v : dir[c][i]) {
    if (v.first == op) return true;
  }
  return false;
}
int solve(int rs, int cs, int rt, int ct) {
  memset(dist, -1, sizeof(dist));
  queue<State> q;
  q.push(State(rs, cs, 0));
  dist[rs][cs][0] = 0;
  while (!q.empty()) {
    State u = q.front();
    q.pop();
    if (u.r == rt and u.c == ct) return dist[u.r][u.c][u.dir];
    char at = g[u.r][u.c];
    for (auto v : dir[at][u.dir]) {
      int nr = u.r + v.second.first, nc = u.c + v.second.second;
      if (ok(nr, nc) and opposite(v, g[nr][nc], u.dir) and
          dist[nr][nc][u.dir] == -1) {
        dist[nr][nc][u.dir] = 1 + dist[u.r][u.c][u.dir];
        q.push(State(nr, nc, u.dir));
      }
    }
    if (dist[u.r][u.c][(u.dir + 1) % MAXD] == -1) {
      dist[u.r][u.c][(u.dir + 1) % MAXD] = 1 + dist[u.r][u.c][u.dir];
      q.push(State(u.r, u.c, (u.dir + 1) % MAXD));
    }
  }
  return -1;
}
int main() {
  fast_io();
  preprocess();
  int rs, cs, rt, ct;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
    }
  }
  cin >> rs >> cs;
  cin >> rt >> ct;
  --rs, --cs;
  --rt, --ct;
  cout << solve(rs, cs, rt, ct) << '\n';
  return 0;
}
