#include <iostream>
using namespace std;
bool BreakRow (int **chocolate, int n, int m){
for (int i = 0; i < n - 1; i++){
bool okRow = true;
for (int j = 0; j < m; j++){
if(chocolate[i][j] == chocolate [i + 1][j]){okRow = false;break;}
}
if (okRow) return true;
}
return false;
}
bool BreakColumn (int **chocolate, int n, int m){
for (int i = 0; i < m - 1; i++){
bool okColumn = true;
for (int j = 0; j < n; j++){
if(chocolate[j][i] == chocolate[j][i + 1]){okColumn = false;break;}
}
if (okColumn) return true;
}
return false;
}
int check (int **chocolate, int n, int m){
if ( BreakRow(chocolate, n, m) || BreakColumn (chocolate, n, m)) cout<<"Yes";
else cout<<"No";
}
int main() {
int n, m;
cin >> n >> m;
int **chocolate = new int* [n];
for(int i = 0; i < n; ++i){
chocolate[i] = new int[m];
}
for( int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> chocolate [i][j];
}
}
check(chocolate, n, m);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCiAKYm9vbCBCcmVha1JvdyAoaW50ICoqY2hvY29sYXRlLCBpbnQgbiwgaW50IG0pewogIGZvciAoaW50IGkgPSAwOyBpIDwgbiAtIDE7IGkrKyl7CiAgICBib29sIG9rUm93ID0gdHJ1ZTsKICAgIGZvciAoaW50IGogPSAwOyBqIDwgbTsgaisrKXsKICAgICAgaWYoY2hvY29sYXRlW2ldW2pdID09IGNob2NvbGF0ZSBbaSArIDFdW2pdKXtva1JvdyA9IGZhbHNlO2JyZWFrO30KICAgIH0KICAgIGlmIChva1JvdykgcmV0dXJuIHRydWU7CiAgfQogIHJldHVybiBmYWxzZTsKfQpib29sIEJyZWFrQ29sdW1uIChpbnQgKipjaG9jb2xhdGUsIGludCBuLCBpbnQgbSl7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBtIC0gMTsgaSsrKXsKICAgIGJvb2wgb2tDb2x1bW4gPSB0cnVlOwogICAgZm9yIChpbnQgaiA9IDA7IGogPCBuOyBqKyspewogICAgICBpZihjaG9jb2xhdGVbal1baV0gPT0gY2hvY29sYXRlW2pdW2kgKyAxXSl7b2tDb2x1bW4gPSBmYWxzZTticmVhazt9CiAgICB9CiAgICBpZiAob2tDb2x1bW4pIHJldHVybiB0cnVlOwogIH0KICByZXR1cm4gZmFsc2U7Cn0KIAppbnQgY2hlY2sgKGludCAqKmNob2NvbGF0ZSwgaW50IG4sIGludCBtKXsKICBpZiAoIEJyZWFrUm93KGNob2NvbGF0ZSwgbiwgbSkgfHwgQnJlYWtDb2x1bW4gKGNob2NvbGF0ZSwgbiwgbSkpIGNvdXQ8PCJZZXMiOwogIGVsc2UgY291dDw8Ik5vIjsKfQogCmludCBtYWluKCkgewogIGludCBuLCBtOwogIGNpbiA+PiBuID4+IG07CiAgaW50ICoqY2hvY29sYXRlID0gbmV3IGludCogW25dOwogIGZvcihpbnQgaSA9IDA7IGkgPCBuOyArK2kpewogICAgY2hvY29sYXRlW2ldID0gbmV3IGludFttXTsKICB9CiAgZm9yKCBpbnQgaSA9IDA7IGkgPCBuOyAgaSsrKXsKICAgIGZvcihpbnQgaiA9IDA7IGogPCBtOyBqKyspewogICAgICBjaW4gPj4gY2hvY29sYXRlIFtpXVtqXTsKICAgIH0KICB9CiAgY2hlY2soY2hvY29sYXRlLCBuLCBtKTsKICByZXR1cm4gMDsKfQo=