#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> matrix(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> matrix[i][j];
}
}
int age1, age2;
cin >> age1 >> age2;
int row1, col1, row2, col2;
bool found1 = false, found2 = false;
for (int i = 0; i < n && !found1; ++i) {
for (int j = 0; j < m && !found1; ++j) {
if (matrix[i][j] == age1) {
row1 = i;
col1 = j;
found1 = true;
}
}
}
for (int i = 0; i < n && !found2; ++i) {
for (int j = 0; j < m && !found2; ++j) {
if (matrix[i][j] == age2) {
row2 = i;
col2 = j;
found2 = true;
}
}
}
if (abs(row1 - row2) <= 1 && abs(col1 - col2) <= 1 && !(row1 == row2 && col1 == col2)) {
cout << "Y" << endl;
} else {
cout << "N" << endl;
}
return 0;
}
/**************************************************************
Problem: 2000
User: zhenghaoxuan
Language: C
Result: Compile Error
****************************************************************/