#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> get_factors(int x, int M, int N, unordered_map<int, vector<pair<int, int>>>& factor_cache) {
if (factor_cache.find(x) != factor_cache.end()) {
return factor_cache[x];
}
vector<pair<int, int>> factors;
for (int a = 1; a * a <= x; ++a) {
if (x % a == 0) {
int b = x / a;
if (a <= M && b <= N) factors.push_back({a, b});
if (b <= M && a <= N && a != b) factors.push_back({b, a});
}
}
factor_cache[x] = factors;
return factors;
}
int main() {
int M, N;
cin >> M >> N;
vector<vector<int>> grid(M + 1, vector<int>(N + 1));
for (int i = 1; i <= M; ++i) {
for (int j = 1; j <= N; ++j) {
cin >> grid[i][j];
}
}
queue<pair<int, int>> q;
q.push({1, 1});
vector<vector<bool>> visited(M + 1, vector<bool>(N + 1, false));
visited[1][1] = true;
unordered_map<int, vector<pair<int, int>>> factor_cache;
while (!q.empty()) {
auto [r, c] = q.front();
q.pop();
if (r == M && c == N) {
cout << "yes" << endl;
return 0;
}
int value = grid[r][c];
vector<pair<int, int>> jumps = get_factors(value, M, N, factor_cache);
for (auto [a, b] : jumps) {
if (!visited[a][b]) {
visited[a][b] = true;
q.push({a, b});
}
}
}
cout << "no" << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2ZWN0b3I8cGFpcjxpbnQsIGludD4+IGdldF9mYWN0b3JzKGludCB4LCBpbnQgTSwgaW50IE4sIHVub3JkZXJlZF9tYXA8aW50LCB2ZWN0b3I8cGFpcjxpbnQsIGludD4+PiYgZmFjdG9yX2NhY2hlKSB7CiAgICBpZiAoZmFjdG9yX2NhY2hlLmZpbmQoeCkgIT0gZmFjdG9yX2NhY2hlLmVuZCgpKSB7CiAgICAgICAgcmV0dXJuIGZhY3Rvcl9jYWNoZVt4XTsKICAgIH0KCiAgICB2ZWN0b3I8cGFpcjxpbnQsIGludD4+IGZhY3RvcnM7CiAgICBmb3IgKGludCBhID0gMTsgYSAqIGEgPD0geDsgKythKSB7CiAgICAgICAgaWYgKHggJSBhID09IDApIHsKICAgICAgICAgICAgaW50IGIgPSB4IC8gYTsKICAgICAgICAgICAgaWYgKGEgPD0gTSAmJiBiIDw9IE4pIGZhY3RvcnMucHVzaF9iYWNrKHthLCBifSk7CiAgICAgICAgICAgIGlmIChiIDw9IE0gJiYgYSA8PSBOICYmIGEgIT0gYikgZmFjdG9ycy5wdXNoX2JhY2soe2IsIGF9KTsKICAgICAgICB9CiAgICB9CgogICAgZmFjdG9yX2NhY2hlW3hdID0gZmFjdG9yczsgCiAgICByZXR1cm4gZmFjdG9yczsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgTSwgTjsKICAgIGNpbiA+PiBNID4+IE47CiAgICAKCiAgICB2ZWN0b3I8dmVjdG9yPGludD4+IGdyaWQoTSArIDEsIHZlY3RvcjxpbnQ+KE4gKyAxKSk7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBNOyArK2kpIHsKICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBOOyArK2opIHsKICAgICAgICAgICAgY2luID4+IGdyaWRbaV1bal07CiAgICAgICAgfQogICAgfQoKCiAgICBxdWV1ZTxwYWlyPGludCwgaW50Pj4gcTsKICAgIHEucHVzaCh7MSwgMX0pOwogICAgCgogICAgdmVjdG9yPHZlY3Rvcjxib29sPj4gdmlzaXRlZChNICsgMSwgdmVjdG9yPGJvb2w+KE4gKyAxLCBmYWxzZSkpOwogICAgdmlzaXRlZFsxXVsxXSA9IHRydWU7CgogICAgdW5vcmRlcmVkX21hcDxpbnQsIHZlY3RvcjxwYWlyPGludCwgaW50Pj4+IGZhY3Rvcl9jYWNoZTsKCiAgICB3aGlsZSAoIXEuZW1wdHkoKSkgewogICAgICAgIGF1dG8gW3IsIGNdID0gcS5mcm9udCgpOwogICAgICAgIHEucG9wKCk7CgogICAgICAgIGlmIChyID09IE0gJiYgYyA9PSBOKSB7CiAgICAgICAgICAgIGNvdXQgPDwgInllcyIgPDwgZW5kbDsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQoKCiAgICAgICAgaW50IHZhbHVlID0gZ3JpZFtyXVtjXTsKICAgICAgICB2ZWN0b3I8cGFpcjxpbnQsIGludD4+IGp1bXBzID0gZ2V0X2ZhY3RvcnModmFsdWUsIE0sIE4sIGZhY3Rvcl9jYWNoZSk7CgoKICAgICAgICBmb3IgKGF1dG8gW2EsIGJdIDoganVtcHMpIHsKICAgICAgICAgICAgaWYgKCF2aXNpdGVkW2FdW2JdKSB7CiAgICAgICAgICAgICAgICB2aXNpdGVkW2FdW2JdID0gdHJ1ZTsKICAgICAgICAgICAgICAgIHEucHVzaCh7YSwgYn0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgCiAgICBjb3V0IDw8ICJubyIgPDwgZW5kbDsKICAgIHJldHVybiAwOwp9