#if 0 愚直解法 #endif // includes {{{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include // #include // #include // #include // }}} using namespace std; using ll = long long; int main() { std::ios::sync_with_stdio(false), std::cin.tie(0); int h, w; cin >> h >> w; vector v(h); int cnt[2] = {}; for(auto &e: v) { cin >> e; for(auto &e2 : e) e2 -= '0', cnt[e2]++; } int ans = 1; for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) { bool ng = 1; for(int k = 0; k < h; k++) { ng &= v[i][j] == v[k][j]; } for(int k = 0; k < w; k++) { ng &= v[i][j] == v[i][k]; } if(ng) ans = 0; if(ans == 0) break; } cout << (ans ? "YES" : "NO") << endl; return 0; }