旗的每一行内颜色相同,相邻行间颜色不同
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define ls rt<<1
#define rs ls1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle (l+r)>>1
#define eps (1e-9)
#define clr_all(x,c) memset(x,c,sizeof(x))
#define clr(x,c,n) memset(x,c,sizeof(x[0])*(n+1))
#define MOD 1000000007
#define inf 100000007
#define pi acos(-1.0)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define M 100+5
char c[M][M];
int main(){
int i,j,m,n,f;
while(~scanf("%d %d",&n,&m)){
getchar();
rep(i,n)gets(c[i]);
f=0;
rep(i,n)
REP(j,1,m)
if(f==0&&c[i][j]!=c[i][j-1])f=1;
rep(j,m)
REP(i,1,n)
if(f==0&&c[i][j]==c[i-1][j])f=1;
if(f==1)puts("NO");
else puts("YES");
}
return 0;
}