#include using namespace std; struct UnionFind { vector< int > data; UnionFind(int sz) { data.assign(sz, -1); } void unite(int x, int y) { x = find(x), y = find(y); if(x != y) { if(data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; } } int find(int k) { if(data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; int main() { int H, W; int sx, sy, gx, gy; string b[50]; cin >> H >> W; cin >> sx >> sy >> gx >> gy; for(int i = 0; i < H; i++) { cin >> b[i]; } --sx, --sy, --gx, --gy; UnionFind tree(H * W); for(int i = 0; i < H; i++) { for(int j = 0; j < W; j++) { if(j > 0 && abs(b[i][j - 1] - b[i][j]) <= 1) tree.unite(i * W + j, i * W + j - 1); if(i > 0 && abs(b[i - 1][j] - b[i][j]) <= 1) tree.unite(i * W + j, i * W + j - W); if(j > 1 && b[i][j - 2] == b[i][j]) tree.unite(i * W + j, i * W + j - 2); if(i > 1 && b[i - 2][j] == b[i][j]) tree.unite(i * W + j, i * W + j - W - W); } } if(tree.find(sy * W + sx) == tree.find(gy * W + gx)) { cout << "YES" << endl; } else { cout << "NO" << endl; } }