//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}
#define int long long
const int MAXN = 5 * 100000 + 10;
int sum = 0,n,m;
int a[MAXN];

bool ok(int i) {
    sum = 0;
    for (int j = 0; j < n; ++j) {
        sum += max(a[j] - j/i , 1LL*0);
    }
    return sum>=m;
}
int32_t main() {
    fio
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n, greater<int>());
    int l = 1;
    int r = n;
    while(l + 1 < r) {
       int mid = l + (r-l) / 2;
       if(ok(mid)) r = mid;
       else {
           l = mid;
       }
    }
    if(ok(l)) cout << l << endl;
    else if(ok(r)) cout << r << endl;
    else puts("-1");
}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 5 * 100000 + 10;
int sum = 0,n,m;
int a[MAXN];
#define int long long
bool ok(int i) {
    sum = 0;
    for (int j = 0; j < n; ++j) {
        sum += max(a[j] + j/i , 1LL*0);
    }
    return sum>=m;
}
int32_t main() {
    fio
    cin >> n >> m;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n, greater<int>());

   int l = 0;
   int r = n;
   while(l < r) {
       int mid = l + (r-l)/2;
       if(ok(mid)) r = mid;
       else {
           l = mid;
       }
   }
   if(ok(l))cout << l << endl;
   else if(ok(r)) cout << r << endl;
   else   puts("-1");

}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 5 * 100000 + 10;
int sum = 0,n,m;
int a[MAXN];
#define int long long
bool ok(int i) {
    sum = 0;
    for (int j = 0; j < n; ++j) {
        sum += max(a[j] + j/i , 1LL*0);
    }
    return sum>=m;
}
int32_t main() {
    fio
    cin >> n >> m;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n, greater<int>());

   int l = 1;
   int r = n;
   while(l < r) {
       int mid = l + (r-l)/2;
       if(ok(mid)) r = mid;
       else {
           l = mid;
       }
   }
   if(ok(l))cout << l << endl;
   else if(ok(r)) cout << r << endl;
   else   puts("-1");

}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 5 * 100000 + 10;
int sum = 0,n,m;
int a[MAXN];
#define int long long
bool ok(int i) {
    sum = 0;
    for (int j = 0; j < n; ++j) {
        sum += max(a[j] - j/i , 1LL*0);
    }
    return sum>=m;
}
int32_t main() {
    fio
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n, greater<int>());
    int l = 1;
    int r = n;
    while(l + 1 < r) {
       int mid = l + (r-l) / 2;
       if(ok(mid)) r = mid;
       else {
           l = mid;
       }
    }
    if(ok(l)) cout << l << endl;
    else if(ok(r)) cout << r << endl;
    else puts("-1");
}


/*

███╗░░██╗░█████╗░██╗░░██╗░█████╗░░█████╗░██████╗░██╗░░██╗
████╗░██║██╔══██╗██║░░██║██╔══██╗██╔══██╗██╔══██╗██║░██╔╝
██╔██╗██║██║░░██║███████║███████║███████║██████╔╝█████═╝░
██║╚████║██║░░██║██╔══██║██╔══██║██╔══██║██╔══██╗██╔═██╗░
██║░╚███║╚█████╔╝██║░░██║██║░░██║██║░░██║██║░░██║██║░╚██╗
╚═╝░░╚══╝░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝

*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define w(x)            int x; cin>>x; while(x--)
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
vi a;
int n,m;

int main(){
FASTIO;

cin>>n>>m;
a = vi(n,0);
rep(i,0,n)
{
    cin>>a[i];
}

sort(all(a));
reverse(all(a));
ll sum =0;
rep(i,0,n)
{
    sum+=a[i];
}

if(sum<m)
{
    cout<<-1;
    return 0;
}

int days = 1;
int k=0;
rep(i,0,n)
{
    if(sum==m)
    {
        days+=n-i;
        break;
    }

    if(sum>=m+k)
    {
         sum=sum - a[i];
         m=m-a[i]+k;
        k++;
    }
    else
    { k=0;
    days++;
    i--;
        /* code */
    }

}
cout<<days<<endl;
return 0;
}


/*

███╗░░██╗░█████╗░██╗░░██╗░█████╗░░█████╗░██████╗░██╗░░██╗
████╗░██║██╔══██╗██║░░██║██╔══██╗██╔══██╗██╔══██╗██║░██╔╝
██╔██╗██║██║░░██║███████║███████║███████║██████╔╝█████═╝░
██║╚████║██║░░██║██╔══██║██╔══██║██╔══██║██╔══██╗██╔═██╗░
██║░╚███║╚█████╔╝██║░░██║██║░░██║██║░░██║██║░░██║██║░╚██╗
╚═╝░░╚══╝░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝

*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define w(x)            int x; cin>>x; while(x--)
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int ll
vi a;
int n,m;

bool ans(int x)
{
    int sum =0;
    rep(i,0,n)
    sum+=max(0ll,a[i] - (i/x));

   if(sum>=m)
   return true;

   return false;

}
signed main(){
FASTIO;

cin>>n>>m;
a = vi(n,0);
rep(i,0,n)
{
    cin>>a[i];
}

sort(all(a));
reverse(all(a));
int l = 0, r = n+1;

int answ=-1;
 while(l+1<r)
 {
     int x = (l+r)/2;
    // cout<<l<<" "<<r<<" "<<x<<endl;
     if(ans(x))
     { answ =x;
         r=x;
     }

     else
     {
         l = x;
     }

 }

 cout<<answ;
 return 0;
}


/*

███╗░░██╗░█████╗░██╗░░██╗░█████╗░░█████╗░██████╗░██╗░░██╗
████╗░██║██╔══██╗██║░░██║██╔══██╗██╔══██╗██╔══██╗██║░██╔╝
██╔██╗██║██║░░██║███████║███████║███████║██████╔╝█████═╝░
██║╚████║██║░░██║██╔══██║██╔══██║██╔══██║██╔══██╗██╔═██╗░
██║░╚███║╚█████╔╝██║░░██║██║░░██║██║░░██║██║░░██║██║░╚██╗
╚═╝░░╚══╝░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝

*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define w(x)            int x; cin>>x; while(x--)
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
vi a;
int n,m;

int main(){
FASTIO;

cin>>n>>m;
a = vi(n,0);
rep(i,0,n)
{
    cin>>a[i];
}

sort(all(a));
reverse(all(a));
ll sum =0;
rep(i,0,n)
{
    sum+=a[i];
}

if(sum<m)
{
    cout<<-1;
    return 0;
}

int days = 0;
int k=0;
rep(i,0,n)
{
    if(sum==m)
    {
        days+=n-i;
        break;
    }

    if(sum>=m+k)
    {
         sum=sum - a[i];
         m=m-a[i]+k;
        k++;
    }
    else
    { k=0;
    days++;
        /* code */
    }

}
cout<<days+1<<endl;
return 0;
}


/*

███╗░░██╗░█████╗░██╗░░██╗░█████╗░░█████╗░██████╗░██╗░░██╗
████╗░██║██╔══██╗██║░░██║██╔══██╗██╔══██╗██╔══██╗██║░██╔╝
██╔██╗██║██║░░██║███████║███████║███████║██████╔╝█████═╝░
██║╚████║██║░░██║██╔══██║██╔══██║██╔══██║██╔══██╗██╔═██╗░
██║░╚███║╚█████╔╝██║░░██║██║░░██║██║░░██║██║░░██║██║░╚██╗
╚═╝░░╚══╝░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝

*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define w(x)            int x; cin>>x; while(x--)
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
vi a;
int n,m;

bool ans(int x)
{
    int sum =0;
    rep(i,0,n)
    sum+=max(0,a[i] - (i/x));

   if(sum>=m)
   return true;

   return false;

}
int main(){
FASTIO;

cin>>n>>m;
a = vi(n,0);
rep(i,0,n)
{
    cin>>a[i];
}

sort(all(a));
reverse(all(a));
int l = 0, r = n+1;

int answ=-1;
 while(l+1<r)
 {
     int x = (l+r)/2;
    // cout<<l<<" "<<r<<" "<<x<<endl;
     if(ans(x))
     { answ =x;
         r=x;
     }

     else
     {
         l = x;
     }

 }

 cout<<answ;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	long long n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	ll l=0; ll r=n;
	while(r-l>1){
		ll i=l+(r-l)/2;
		ll k=1, h=i;
		ll d=0;
		long long ans=0;
		while(k<=n){
			ans += max(ll(0), ll(vs[h]-vs[k-1]-(i*d)));
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans<m)l=i;
		else r=i;
	}
	cout << r << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	long long n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	ll l=1; ll r=n;
	while(r-l>1){
		ll i=l+(r-l)/2;
		ll k=1, h=i;
		ll d=0;
		long long ans=0;
		while(k<=n){
			ans += max(ll(0), ll(vs[h]-vs[k-1]-(i*d)));
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans<m)l=i;
		else r=i;
	}
	ll k=1, h=l;
	ll d=0;
	long long ans=0;
	while(k<=n){
		ans += max(ll(0), ll(vs[h]-vs[k-1]-(l*d)));
		k=h+1;
		h=min(n,h+l);
		d++;
	}
	if(ans>=m){
		cout << l << endl;
	}
	else{
		cout << r << endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	long long n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	ll l=0; ll r=n;
	while(r-l>1){
		ll i=l+(r-l)/2;
		ll k=1, h=i;
		ll d=0;
		long long ans=0;
		while(k<=n){
			ll tp = vs[h]-vs[h-1]-d;
			ll bt = vs[k]-vs[k-1]-d;
			if(bt>=0){
				ans+=vs[h]-vs[k-1]-((h-(k-1))*d);
			}
			else if(tp>=0 && bt<0){
				for(int w=k; w<=h; w++)
					ans += max(ll(0), (vs[w]-vs[w-1])-d);
			}
			else ans+=0;
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans<m)l=i;
		else r=i;
	}
	cout << r << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	int l=1; int r=n;
	while(r-l>1){
		int i=l+(r-l)/2;
		int k=1, h=i;
		int d=0;
		long long ans=0;
		while(k<=n){
			ans += max(ll(0), vs[h]-vs[k-1]-(i*d));
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans<m)l=i;
		else r=i;
	}
	int k=1, h=l;
	int d=0;
	long long ans=0;
	while(k<=n){
		ans += max(ll(0), vs[h]-vs[k-1]-(l*d));
		k=h+1;
		h=min(n,h+l);
		d++;
	}
	if(ans>=m){
		cout << l << endl;
	}
	else{
		cout << r << endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	long long n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	ll l=0; ll r=n;
	while(r-l>1){
		ll i=l+(r-l)/2;
		ll k=1, h=i;
		ll d=0;
		long long ans=0;
		while(k<=n){
			ans += max(ll(0), ll(vs[h]-vs[k-1]-((h-(k-1))*d)));
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans<m)l=i;
		else r=i;
	}
	cout << r << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	long long n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	ll l=0; ll r=n;
	while(r-l>1){
		ll i=l+(r-l)/2;
		ll k=1, h=i;
		ll d=0;
		long long ans=0;
		while(k<=n){
			ll tp = vs[h]-vs[h-1]-d;
			ll bt = vs[k]-vs[k-1]-d;
			if(bt>=0 && tp>=0){
				ans+=vs[h]-vs[k-1]-((h-(k-1))*d);
			}
			else if(tp<0 && bt<0)ans+=0;
			else{
				for(int w=k; w<=h; w++)
					ans += max(ll(0), (vs[w]-vs[w-1])-d);
			}
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans<m)l=i;
		else r=i;
	}
	cout << r << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	long long n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	ll l=1; ll r=n;
	while(r-l>1){
		ll i=l+(r-l)/2;
		ll k=1, h=i;
		ll d=0;
		long long ans=0;
		while(k<=n){
			ans += max(ll(0), ll(vs[h]-vs[k-1]-(i*d)));
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans<=m)l=i;
		else r=i;
	}
	ll k=1, h=l;
	ll d=0;
	long long ans=0;
	while(k<=n){
		ans += max(ll(0), ll(vs[h]-vs[k-1]-(l*d)));
		k=h+1;
		h=min(n,h+l);
		d++;
	}
	if(ans>=m){
		cout << l << endl;
	}
	else{
		cout << r << endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	long long n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	ll l=0; ll r=n;
	while(r-l>1){
		ll i=l+(r-l)/2;
		ll k=1, h=i;
		ll d=0;
		long long ans=0;
		while(k<=n){
			ll aux = vs[h]-vs[k-1]-((h-k+1)*d);
			if(aux>=0) ans+=aux;
			else{
				for(int w=k; w<=h; w++)
					ans += max(ll(0), (vs[w]-vs[w-1])-d);
			}
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans<m)l=i;
		else r=i;
	}
	cout << r << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	long long vs[n+1];
	vs[0]=0;
	for(int i=1; i<=n; i++){
		cin >> vs[i];
	}
	sort(vs+1, vs+n+1);
	reverse(vs+1, vs+n+1);
	for(int i=1; i<=n; i++){
	       vs[i]+=vs[i-1];
	}
	if(vs[n]<m){
		cout << -1 << endl;
		return 0;
	}
	int l=1; int r=n;
	while(r-l>1){
		int i=l+(r-l)/2;
		int k=1, h=i;
		int d=0;
		long long ans=0;
		while(k<=n){
			ans += max(ll(0), vs[h]-vs[k-1]-(i*d));
			k=h+1;
			h=min(n,h+i);
			d++;
		}
		if(ans>m)r=i;
		else l=i;
	}
	int k=1, h=l;
	int d=0;
	long long ans=0;
	while(k<=n){
		ans += max(ll(0), vs[h]-vs[k-1]-(l*d));
		k=h+1;
		h=min(n,h+l);
		d++;
	}
	if(ans>=m){
		cout << l << endl;
	}
	else{
		cout << r << endl;
	}

}


// Problem : D2. Coffee and Coursework (Hard Version)
// Contest : Codeforces - Codeforces Round #540 (Div. 3)
// URL : https://codeforces.com/contest/1118/problem/D2
// Memory Limit : 256 MB
// Time Limit : 2500 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 2e5+5;
int n,m;
int arr[N],sum=0;
void input()
{
	cin>>n>>m;
	for(int i=0;i<n;++i)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	sort(arr,arr+n);
	reverse(arr,arr+n);
}
bool help(int mid)
{
	int pages = 0;
	for(int i=0;i<n;++i)
	{
		pages+= max(0ll,arr[i]-i/mid);
	}
	return pages>=m;
}
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	input();
    	if(m>sum)
    	{
    		cout<<-1;
    		return 0;
    	}
    	int low = 1,high = m,mid,ans = -1;
    	while(low<=high)
    	{
    		mid = low+ (high-low)/2;
    		if(help(mid))
    		{
    			ans = mid;
    			high = mid-1;
    		}
    		else
    		low = mid+1;
    	}
    	cout<<ans<<"\n";
    }
    return 0;
}


// Problem : D2. Coffee and Coursework (Hard Version)
// Contest : Codeforces - Codeforces Round #540 (Div. 3)
// URL : https://codeforces.com/contest/1118/problem/D2
// Memory Limit : 256 MB
// Time Limit : 2500 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 2e5+5;
int n,m;
int arr[N],sum=0;
void input()
{
	cin>>n>>m;
	for(int i=0;i<n;++i)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	sort(arr,arr+n);
	reverse(arr,arr+n);
}
bool help(int mid)
{
	int pages = 0;
	for(int i=0;i<n;++i)
	{
		pages+= max(0ll,arr[i]-i/mid);
	}
	return pages>=m;
}
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	input();
    	if(m>sum)
    	{
    		cout<<-1;
    		return 0;
    	}
    	int low = 1,high = m,mid,ans = -1;
    	while(low<=high)
    	{
    		mid = low+ (high-low)/2;
    		if(help(mid))
    		{
    			ans = mid;
    			high = mid-1;
    		}
    		else
    		low = mid+1;
    	}
    	cout<<ans<<"\n";
    }
    return 0;
}


// Problem : D2. Coffee and Coursework (Hard Version)
// Contest : Codeforces - Codeforces Round #540 (Div. 3)
// URL : https://codeforces.com/contest/1118/problem/D2
// Memory Limit : 256 MB
// Time Limit : 2500 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 2e5+5;
int n,m;
int arr[N],sum=0;
void input()
{
	cin>>n>>m;
	for(int i=0;i<n;++i)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	sort(arr,arr+n);
	reverse(arr,arr+n);
}
bool help(int mid)
{
	int pages = 0;
	for(int i=0;i<mid-1;++i)
	pages+=arr[i];
	int xxx = 0,i=mid-1;
	while(i<n)
	{
		if(arr[i]-xxx<=0)
		break;
		pages+= (arr[i]-xxx);
		++xxx;++i;
	}
	return pages>=m;
}
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	input();
    	if(m>sum)
    	{
    		cout<<-1;
    		return 0;
    	}
    	int low = 1,high = m,mid,ans = -1;
    	while(low<=high)
    	{
    		mid = low+ (high-low)/2;
    		if(help(mid))
    		{
    			ans = mid;
    			high = mid-1;
    		}
    		else
    		low = mid+1;
    	}
    	cout<<ans<<"\n";
    }
    return 0;
}


// Problem : D2. Coffee and Coursework (Hard Version)
// Contest : Codeforces - Codeforces Round #540 (Div. 3)
// URL : https://codeforces.com/contest/1118/problem/D2
// Memory Limit : 256 MB
// Time Limit : 2500 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 2e5+5;
int n,m;
int arr[N],sum=0;
void input()
{
	cin>>n>>m;
	for(int i=0;i<n;++i)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	sort(arr,arr+n);
	reverse(arr,arr+n);
}
bool help(int mid)
{
	int pages = 0;
	for(int i=0;i<n;++i)
	{
		pages+= max(0,arr[i]-i/mid);
	}
	return pages>=m;
}
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	input();
    	if(m>sum)
    	{
    		cout<<-1;
    		return 0;
    	}
    	int low = 1,high = m,mid,ans = -1;
    	while(low<=high)
    	{
    		mid = low+ (high-low)/2;
    		if(help(mid))
    		{
    			ans = mid;
    			high = mid-1;
    		}
    		else
    		low = mid+1;
    	}
    	cout<<ans<<"\n";
    }
    return 0;
}


//      https://codeforces.com/problemset/problem/1118/D2

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#ifdef EVAL
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
#endif

int main(){

    int n;
    cin >> n;

    int m;
    cin >> m;

    vector<long long int> cups(n);
    for(int i=0; i<n; i++){
        cin >> cups[i];
    }

    long long int sum = 0;

    sort(cups.rbegin(), cups.rend());

    long long int a=0, b=n, mid = (a+b)/2;
    long long int pos,k;
    while(a<b){
        //Prendiamo le prime mid tazze dal vettore e le sommiamo
        sum=0;
        k=0;

        for(pos=0; pos<n; pos++){
            if(pos && (!(pos%mid))) k++;
            sum += (cups[pos] - k)>0?(cups[pos] - k):0;
        }

        if(sum >= m){
            b = mid;
        }
        else{
            a = mid+1;
        }
        mid = (a+b)/2;
    }

    if(mid == n && sum < m) cout << -1 << endl;
    else cout << mid << endl;

	return 0;
}


//      https://codeforces.com/problemset/problem/1118/D2

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#ifdef EVAL
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
#endif

int main(){

    int n;
    cin >> n;

    int m;
    cin >> m;

    vector<long long int> cups(n);
    for(int i=0; i<n; i++){
        cin >> cups[i];
    }

    long long int sum = 0;

    sort(cups.rbegin(), cups.rend());

    long long int a=0, b=n, mid = (a+b)/2;
    long long int pos,k;
    while(a<b){
        //Prendiamo le prime mid tazze dal vettore e le sommiamo
        sum=0;
        k=0;

        for(pos=0; pos<n; pos++){
            if(pos && (!(pos%mid))) k++;
            sum += (cups[pos] - k)>0?(cups[pos] - k):0;
        }

        if(sum >= m){
            b = mid;
        }
        else{
            a = mid+1;
        }
        mid = (a+b)/2;
    }

    if(sum < m) cout << -1 << endl;
    else cout << mid << endl;

	return 0;
}


//      https://codeforces.com/problemset/problem/1118/D2

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#ifdef EVAL
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
#endif

int main(){

    int n;
    cin >> n;

    int m;
    cin >> m;

    vector<long long int> cups(n);
    for(int i=0; i<n; i++){
        cin >> cups[i];
    }

    long long int sum = 0;

    sort(cups.rbegin(), cups.rend());

    long long int a=1, b=n, mid = (a+b)/2;
    long long int pos,k;
    while(a<b){
        //Prendiamo le prime mid tazze dal vettore e le sommiamo
        sum=0;
        k=0;

        for(pos=0; pos<n; pos++){
            if(pos && (!(pos%mid))) k++;
            sum += (cups[pos] - k)>0?(cups[pos] - k):0;
        }

        if(sum >= m){
            b = mid;
        }
        else{
            a = mid+1;
        }
        mid = (a+b)/2;
    }

    if(mid == n && sum < m) cout << -1 << endl;
    else cout << mid << endl;

	return 0;
}


//      https://codeforces.com/problemset/problem/1118/D2

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#ifdef EVAL
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
#endif

int main(){

    int n;
    cin >> n;

    int m;
    cin >> m;

    vector<long long int> cups(n);
    for(int i=0; i<n; i++){
        cin >> cups[i];
    }

    long long int sum = 0;

    sort(cups.rbegin(), cups.rend());

    long long int a=1, b=n, mid = (a+b)/2;
    long long int pos,k,mass=-2e9;
    while(a<b){
        //Prendiamo le prime mid tazze dal vettore e le sommiamo
        sum=0;
        k=0;

        for(pos=0; pos<n; pos++){
            if(pos && (!(pos%mid))) k++;
            sum += (cups[pos] - k)>0?(cups[pos] - k):0;
        }
        mass = max(mass, sum);

        if(sum >= m){
            b = mid;
        }
        else{
            a = mid+1;
        }
        mid = (a+b)/2;
    }

    if(mass < m) cout << -1 << endl;
    else cout << mid << endl;

	return 0;
}


//      https://codeforces.com/problemset/problem/1118/D2

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#ifdef EVAL
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
#endif

int main(){

    int n;
    cin >> n;

    int m;
    cin >> m;

    vector<long long int> cups(n);
    for(int i=0; i<n; i++){
        cin >> cups[i];
    }

    long long int sum = 0;

    sort(cups.rbegin(), cups.rend());

    long long int a=1, b=n+1, mid = (a+b)/2;
    long long int pos,k,mass=-2e9;
    while(a<b){
        //Prendiamo le prime mid tazze dal vettore e le sommiamo
        sum=0;
        k=0;

        for(pos=0; pos<n; pos++){
            if(pos && (!(pos%mid))) k++;
            sum += (cups[pos] - k)>0?(cups[pos] - k):0;
        }
        mass = max(mass, sum);
//        cout << sum << "\t" << mid << endl;
//        cout << a << " " << b << endl;

        if(sum >= m){
            b = mid;
        }
        else{
            a = mid+1;
        }
        mid = (a+b)/2;
    }

    if(mass < m) cout << -1 << endl;
    else cout << mid << endl;

	return 0;
}

/*
100 10000
93 99 95 105 94 108 104 104 102 112 106 82 114 104 88 107 105 104 93 96 103 109 105 82 107 95 83 93 120 115 96 104 96 86 87 102 103 108 97 84 108 117 109 107 80 87 102 107 88 97 96 101 101 114 106 103 99 101 105 102 85 94 98 101 115 100 91 92 108 105 94 110 91 89 119 119 93 103 101 84 87 81 105 112 109 102 101 112 98 96 98 112 96 90 101 104 100 98 106 80

*/


//      https://codeforces.com/problemset/problem/1118/D2

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#ifdef EVAL
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
#endif

int main(){

    int n;
    cin >> n;

    int m;
    cin >> m;

    vector<long long int> cups(n);
    for(int i=0; i<n; i++){
        cin >> cups[i];
    }

    long long int sum = 0;

    sort(cups.rbegin(), cups.rend());

    long long int a=1, b=n+1, mid = (a+b)/2;
    long long int pos,k,mass=-2e9;
    while(a<b){
        //Prendiamo le prime mid tazze dal vettore e le sommiamo
        sum=0;
        k=0;

        for(pos=0; pos<n; pos++){
            if(pos && (!(pos%mid))) k++;
            sum += (cups[pos] - k)>0?(cups[pos] - k):0;
        }
        mass = max(mass, sum);
        cout << sum << "\t" << mid << endl;
        cout << a << " " << b << endl;

        if(sum >= m){
            b = mid;
        }
        else{
            a = mid+1;
        }
        mid = (a+b)/2;
    }

    if(mass < m) cout << -1 << endl;
    else cout << mid << endl;

	return 0;
}

/*
100 10000
93 99 95 105 94 108 104 104 102 112 106 82 114 104 88 107 105 104 93 96 103 109 105 82 107 95 83 93 120 115 96 104 96 86 87 102 103 108 97 84 108 117 109 107 80 87 102 107 88 97 96 101 101 114 106 103 99 101 105 102 85 94 98 101 115 100 91 92 108 105 94 110 91 89 119 119 93 103 101 84 87 81 105 112 109 102 101 112 98 96 98 112 96 90 101 104 100 98 106 80

*/


//      https://codeforces.com/problemset/problem/1118/D2

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#ifdef EVAL
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
#endif

int main(){

    int n;
    cin >> n;

    int m;
    cin >> m;

    vector<long long int> cups(n);
    for(int i=0; i<n; i++){
        cin >> cups[i];
    }

    long long int sum = 0;

    sort(cups.rbegin(), cups.rend());

    long long int a=0, b=n, mid = (a+b)/2;
    long long int pos,k;
    while(a<b){
        //Prendiamo le prime mid tazze dal vettore e le sommiamo
        sum=0;
        k=0;

        for(pos=0; pos<n; pos++){
            if(pos && (!(pos%mid))) k++;
            sum += (cups[pos] - k)>0?(cups[pos] - k):0;
        }

        if(sum >= m){
            b = mid;
        }
        else{
            a = mid+1;
        }
        mid = (a+b)/2;
    }

    if(sum < m) cout << -1 << endl;
    else cout << mid << " tua mamma" << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,q,j,sum=0;
	cin>>n>>q;
	j=1;
	long long a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a,a+n);
	if(q>sum)
	cout<<-1;
	else
	{
		long long u=sum-q,in=n-1,se=-1;
		while(q>=0)
		{
			se++;
			if(u-se>=0)
			{
				q=q-a[in]+se;
				u=u-se;
				in--;
			}
			else
			{
				q=q-a[in];
				se=0;
				j++;
				in--;
			}
			if(u==0)
			{
				j=j+in+1;
				break;
			}
		}
		cout<<j;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;

int main()
{
	ll n,m,sum=0;
	cin>>n>>m;
	ll a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum=sum+a[i];
	}
	if(sum<m)
	{
		cout<<-1;
		exit(0);
	}
	if(sum==m)
	{
		cout<<n;
		exit(0);
	}
	sort(a,a+n,greater<ll>());
	ll first=1;
	ll last=n;
	ll mid;
	while(first!=last)
	{
		mid=(first+last)/2;
		ll k=mid;
		ll val=0;
		for(int i=0;i<k;i++)
		val=val+a[i];
		if(val>m)
		last=mid;
		else
		{
			ll se=1;
			ll j=k;
			ll loop;
			bool f=0;
			while(j<n)
			{
				loop=k;
				while(loop--)
				{
					if(a[j]-se>0)
					{
						val = val +a[j]-se;
					}
					else
					{
						f=1;
						break;
					}
					j++;
				}
				se++;
				if(f)
				break;
			}
			if(val>m)
			last=mid;
			else
			first=mid;
		}
	}
	cout<<first;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;

int main()
{
	ll n,m,sum=0;
	cin>>n>>m;
	ll a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum=sum+a[i];
	}
	if(sum<m)
	{
		cout<<-1;
		exit(0);
	}
	if(sum==m)
	{
		cout<<n;
		exit(0);
	}
	sort(a,a+n,greater<ll>());
	ll first=1;
	ll last=n;
	ll mid;
	ll ans;
	while(first<=last)
	{
		mid=(first+last)/2;
		ll k=mid;
		ll val=0;
		for(int i=0;i<k;i++)
		val=val+a[i];
		if(val>=m)
		{
			ans=mid;
			last=mid-1;
		}

		else
		{
			ll se=1;
			ll j=k;
			ll loop;
			bool f=0;
			while(j<n)
			{
				loop=k;
				while(loop--)
				{
					if(a[j]-se>0)
					{
						val = val +a[j]-se;
					}
					else
					{
						f=1;
						break;
					}
					j++;
				}
				se++;
				if(f)
				break;
			}
			if(val>=m)
			{
				ans=mid;
				last=mid-1;
			}
			else
			first=mid+1;
		}
	}
	cout<<ans;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <stack>
#include <cctype>
#include <map>
#include <regex>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int iLength, iWidth,i,j;
	int arrFlag[100][100];
	char chrInput;
	cin >> iLength >> iWidth;
	for (i = 0; i <= iLength - 1; ++i){
		for (j = 0; j <= iWidth - 1; ++j){
			cin >> chrInput;
			arrFlag[i][j] = chrInput - '0';
		}
	}
	for (i = 0; i <= iLength - 1; ++i){
		for (j = 1; j <= iWidth - 1; ++j){
			if (arrFlag[i][j] != arrFlag[i][0]){
				cout << "NO";
				goto endapp;
			}
		}
	}
	for (i = 1; i <= iLength - 1; ++i){
		if (arrFlag[i][0] == arrFlag[i - 1][0]){
			cout << "NO";
			goto endapp;
		}
	}
	cout << "YES";
endapp:
	//system("pause > nul");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;

bool cmp(int qwq,int x){
	int a=qwq%10;
	int b=qwq/10%10;
	while(x!=-1){
		if(a==b){
			b/10%10;
			x--;
		}
		else{
			return false;
		}
	}
	return true;
}

int  flag;
int main(){
	cin>>n>>m;
	cin>>flag;
	int last=flag%10;
	if(cmp(flag,m)!=true){
		cout<<"NO"<<endl;
		return 0;
	}
	else for(int i=1;i<n;i++){
		cin>>flag;
		if(cmp(flag,m)==false||last==flag%10){
			cout<<"NO"<<endl;
			return 0;
		}
		if(cmp(flag,m)==true&&last!=flag%10)last=flag%10;
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
string s;
char c;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {

    	cin>>s;
    	if(s[0]==c&&i!=1){printf("NO");return 0;}
    	c=s[0];
        for(int j=1;j<s.size();j++)
            if(s[j]!=c) {printf("NO");return 0;}
    }
    printf("YES\n");
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
char a[109][109];
int n,m;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
			a[i][j]-='0';
		}
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]==a[i+1][j])
			{
				cout<<"NO";
				return 0;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(a[i][j]!=a[i][j+1])
			{
				cout<<"NO";
				return 0;
			}
		}
	}
	cout<<"YES";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,a[105][105];
int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		scanf("%1d",&a[i][1]);
		for(int j = 2; j <= m; j++) {
			scanf("%1d",&a[i][j]);
			if(a[i][j] != a[i][j - 1]) {
				cout << "NO";
				return 0;
			}
		}
		if(i > 1 && a[i][m] == a[i - 1][m]) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	char mp[n+10][m+10];
	for(int i=1 ; i<=n ; i++){
		for(int j=1 ; j<=m ; j++){
			cin >> mp[i][j];
		}
	}
	for(int i=2 ; i<n ; i++){
		int flag = 0;
		for(int j=2 ; j<=m ; j++){
			if (mp[i][j] != mp[i][j-1])
				flag = 1;
		}
		if (flag)
			continue;
		for(int j=1 ; j<=m ; j++){
			if (mp[i][j] == mp[i-1][j] || mp[i][j] == mp[i+1][j] || mp[i-1][j] == mp[i+1][j])
				flag = 1;
		}
		if ( !flag ){
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int ans[n][m];
	memset(ans,0,sizeof(ans));
	for(int i=0;i<n;i++)
		cin>>ans[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(j&&a[i][j]!=a[i][j-1]){
				cout<<"NO"<<endl;
				return 0;
			}
		}
		if(i&&a[i][0]==a[i-1][0]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
char a[100+5][100+5];
int main(){
	int n,m,i,j;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(i=1;i<=n;i++){
		if(i!=n){
			for(j=1;j<=m;j++){
				if(a[i][j]==a[i+1][j]){
					cout<<"NO"<<endl;
					return 0;
				}
			}
		}
		for(j=1;j<m;j++){
			if(a[i][j]!=a[i][j+1]){
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int y[3]={1,-1};
char x[10];
string flag[102];
//bool f;
int main(){
	int i,j,k;
	int x1,y1;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>flag[i];
	}
	for(i=1;i<=n;i++){
		for(j=0;j<m-1;j++){
			if(flag[i][j]!=flag[i][j+1]){
				cout<<"NO";
				return 0;
			}
		}
		for(j=0;j<m;j++){
			for(k=0;k<=1;k++){
				x1=i;
				x1+=y[k];
				if(x1<1||x1>n){
					continue;
				}else{
					if(flag[x1][j]==flag[i][j]){
						cout<<"NO";
						return 0;
				    }
				}
			}
		}
	}
	cout<<"YES";
	return 0;
}


#include<iostream>
using namespace std;
int n,m,i,j;
char nm[110][110];
bool flag=0;
int main(){
	cin>>n>>m;
	for(i=0;i<n;i++)
		cin>>nm[i];

	for(i=0;i<n;i++)
	for(j=0;j<m;j++){
		if(nm[i][j]==nm[i-1][j]||nm[i][j]==nm[i+1][j])
		flag=1;
		if(nm[i][j]!=nm[i][j-1]||nm[i][j]!=nm[i][j+1])
		flag=1;
	}
	if(flag==0)
	cout<<"YES";
	else
	cout<<"NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[105][105];
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(i!=n-1&&a[i][0]==a[i+1][0]){
            cout<<"NO"<<endl;
            return 0;
        }
        for(int j=0;j<m;j++){
            if(a[i][j]!=a[i][0]){
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }cout<<"YES"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	cin>>n>>m;
	char color[n][m];
	int check[n],cc=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>color[i][j];
			if(j>0&&color[i][j]!=color[i][j-1]){
				cc=1;
			}
			//cout<<"A"<<endl;
		}
		check[i]=color[i][0];
	}
	if(cc==1){
		//cout<<"A"<<endl;
		cout<<"NO";
		return 0;
	}
	for(int i=0;i<n;i++){
		if(i>0&&check[i]==check[i-1]){
			//cout<<"B"<<endl;
		    cout<<"NO";
		    return 0;
		}
	}
	cout<<"YES";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	register int n,m,a[110],ln;
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;i++)
	{
		memset(a,0,sizeof(a));
		bool flag=0;
		for(register int k=1;k<=m;k++)
			scanf("%d",&a[k]);
		for(register int k=1;k<=m;k++)
			if(k!=m&&a[k]!=a[k+1]) flag=1;
		if(i==1) ln=-0x7fffffff;

		if(ln==a[1]||flag==1)
		{
			puts("NO");
			return 0;
		}
		else ln=a[1];
	}
	puts("YES");
	return 0;
}


#include <iostream>
using namespace std;
char f,last=' ';     //last初始化，保证第一次比较上一行时的结果一定为false
int main(){
    int n,m;
    char ch,last=' ';
    cin>>n>>m;
    for(register int i=1;i<=n;i++)
    {
        cin>>ch;
        for(register int j=2;j<=m;j++)
        {
            char t;
            cin>>t;
            if(t!=ch) {cout<"NO"<<endl;return 0;}
        }
        if(last==ch) {cout<"NO"<<endl;return 0;}
        last=ch;
    }
    cout<<"YES"<<endl;
    return 0;
}


//luogu-siyuan
#include<cstdio>
using namespace std;
int n,m;
char f,last=' ';
int main(){
    scanf("%d%d",&n,&m);
    for(register int i=1;i<=n;i++){
        f=getchar();
        while(f<'0'||f>'9')  f=getchar();
        for(register int j=2;j<=m;j++){
            char t=getchar();
            if(t!=f) {printf("NO");return 0;}
        }
        if(last==f){printf("NO");return 0;}last=f;
    }
    printf("YES");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
string s;
int main()
{
    cin>>n>>m;
    int t=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        if(s[0]==t)
        {
            cout<<"NO";
            return 0;
        }
        for(int j=1;j<s.size();j++)
        {
            if(s[j]-'0'==t||s[j]!=s[j-1])
            {
                cout<<"NO";
                return 0;
            }
        }
        t=s[1];
    }
    cout<<"YES";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s[105];
int n,m;
void pd()
{
	for(int i=0;i<n;i++)
		for(int j=1;j<m;j++)
			if(s[i][j]!=s[i][j-1])
			{
				printf("NO");
				exit(0);
			}
	for(int i=1;i<n;i++)
		for(int j=0;j<m;j++)
			if(s[i][j]==s[i-1][j])
			{
				printf("NO");
				exit(0);
			}
	printf("YES");
	exit(0);
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	pd();
}


#include<iostream>
using namespace std;
int n,m;
char a[1001][1001],jl;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(int i=0;i<n;i++)
	{
		jl=a[i][0];
		for(int j=1;j<m;j++)
		{
			if(a[i][j]!=jl)
			{
				cout<<"NO";
				return 0;
			}
		}
	}
	for(int i=0;i<n-1;i++)
	{
		jl=a[i][0];
		if(a[i+1][0]==jl)
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,j;
	char a[101][101];
	cin>>n>>m;
	for(i=0;i<n;++i)
	cin>>a[i];
	for(i=0;i<n;++i)
	{
	if(i!=n-1&&a[i][0]==a[i+1][0])
	{
	cout<<"NO";
	return 0;
	}
	for(j=0;j<m;++j)
    if(a[i][j]!=a[i][0])
    {
    cout<<"NO";
    return 0;
	}
	}
	cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    bool flag;
    char ch, first, last;
    cin >> n >> m;
    flag = true;
    for (int i = 0; i < n; i++) {
        cin >> first;
        for (int j = 1; j < m; j++) {
            cin >> ch;
            if (ch != first) { cout << "NO" << endl; flag = false; return 0; }
        }
        if (last == first) { cout << "NO" << endl; flag = false; return 0; }
        last = first;
    }
    if (flag) { cout << "YES" << endl; }
    return 0;
}
/*
dsadadasd
das
d
as
da*/


#include <cstdio>
#include <iostream>
using namespace std;

int a[105][105];
int n,m;

bool judge(int i)
{
	for(int j=2;j<=m;j++)
		if(a[i][1]!=a[i][j]) return false;
	return true;
}

int main()
{
	char ch;
	bool flag=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			cin>>ch;
			a[i][j]=ch-'0';
		}
	if(!judge(1)) flag=1;
	for(int i=2;i<=n;i++)
		if(!judge(i) || a[i-1][1]==a[i][1])
			flag=1;
	if(!flag) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,i,j;
char flag[101][101];
int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
    	for(j=1;j<=m;j++)
    	cin>>flag[i][j];
	}
	for(i=1;i<=n;i++)
    {
    	if(i!=n&&flag[i][1]==flag[i+1][1])
    	{
    		cout<<"NO";
    		return 0;
		}
		for(j=1;j<=m;j++)
		{
			if(flag[i][j]!=flag[i][1])
    		{
    			cout<<"NO";
    			return 0;
			}
		}
	}
	cout<<"YES";
    return 0;
}


#include<cstdio>
using namespace std;
int n,m;
char f,last=' ';
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        f=getchar();
        while(f<'0'||f>'9')
            f=getchar();
        for(int j=2;j<=m;j++)
        {
            char t=getchar();
            if(t!=f)
            {
                printf("NO");
                return 0;
            }
        }
        if(last==f)
        {
            printf("NO");
            return 0;
        }
        last=f;
    }
    printf("YES");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char e[n][m];
    int flag=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        cin>>e[i][j];
    for(int i=0;i<n;i++)
    {
        char t=e[i][0];
        for(int j=0;j<m;j++)
        {
            if(t!=e[i][j]) flag=1;
        }
    }
    for(int i=0;i<n-1;i++)
    {
        if(e[i][0]==e[i+1][0]) flag=1;
    }
    if(flag) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<queue>
#define int long long
#define maxn 100005
#define inf 2147483647
#define mod 1000000009
#define eps 1e-6
#define pi acos(-1.0)
#define de(x) ((x)*(x))
using namespace std;
inline int read(){
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
    return x*f;
}
char ch,last;
signed main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++){
		ch=getchar();
		while(!isdigit(ch)) ch=getchar();
		for(int j=2;j<=m;j++){
			char c=getchar();
			if(c!=ch) return puts("NO"),0;
		}
		if(last==ch) return puts("NO"),0;
		last=ch;
	}
	puts("YES");
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n, m;
    bool flag = true;
    cin >> n >> m;
    char a[n][m];
    for(int i = 0; i <= n - 1; i++)
    {
        for(int j = 0; j <= m - 1; j++)
        {
            cin >> a[i][j];
        }
    }
    for(int i = 0; i <= n - 1; i++)
    {
        for(int j = 0; j <= m - 2; j++)
        {
            if(a[i][j] != a[i][j + 1])
            {
                flag = false;
            }
        }
    }
    for(int i = 0; i <= n - 1; i++)
    {
        for(int j = 0; j <= m - 2; j++)
        {
            if(a[i][j] == a[i + 1][j])
            {
                flag = false;
            }
        }
    }
    if(!flag)
    {
        cout << "NO\n";
    }
    else
    {
        cout << "YES\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,t=0;
char a[110][110];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		{
			bool flag=true;
			for(int j=2;j<=m;j++)
				{
					if(a[i][j]!=a[i][j-1])
					{
						flag=false;break;
					}
					if(a[i][j]==a[i-1][j])
					{
						flag=false;break;
					}
				}
			if(!flag)
				{
					t=1;break;
				}
		}
	if(t==0) cout<<"YES";
	else cout<<"NO";
	return 0;
}


#include<cstring>
#include<cstdio>
#include<cctype>
#define ll long long
#define fr(c,a,b) for(int c=a;c<=b;c++)
#define rf(c,a,b) for(int c=a;c>=b;c--)
const int Max=0x3f3f3f3f;
const int Min=-1;
int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x){return x>0?x:-x;}
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int n=read(),m=read();
char a,b,c;
int main()
{
	fr(i,1,n)
	{
		a=getchar();
		while(!isdigit(a))a=getchar();
		fr(j,2,m)
		{
			b=getchar();
			if(a!=b)
			{
				puts("NO");
				return 0;
			}
		}
		if(a==c)
		{
			puts("NO");
			return 0;
		}
		c=a;
	}
	puts("YES");
	return 0;
}


#include <bits/stdc++.h>
/*dsada
das
d
a
da
d
a
da
d
asd
*/
using namespace std;
int main() {
    int n, m;
    bool flag;
    char ch, first, last;
    cin >> n >> m;
    flag = true;
    for (int i = 0; i < n; i++) {
        cin >> first;
        for (int j = 1; j < m; j++) {
            cin >> ch;
            if (ch != first) { cout << "NO" << endl; flag = false; return 0; }
        }
        if (last == first) { cout << "NO" << endl; flag = false; return 0; }
        last = first;
    }
    if (flag) { cout << "YES" << endl; }
    /*???????*/
    return 0;
}
/*
dsadadasd
das
d
as
da*/


#include<iostream>
using namespace std;
int main()
{
	int n,m;
	string s[120];
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n-1;j++)
		{
			if((s[i][j]-'0')!=(s[i][j+1]-'0'))
			{
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}
	for(int i=0;i<n-1;i++)
	{
		if((s[i][0]-'0')==(s[i+1][0]-'0'))
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<iostream>
using namespace std;
char a[100][100];
main()
{
	int n,m;
	bool flag=true;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			char gog=a[i][0];
			if(gog!=a[i][j])flag=false;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++){
		if(!flag)break;
		if(a[i][j]==a[i+1][j]||a[i][j]==a[i-1][j])
		flag=false;}
	}
	if(!flag)cout<<"NO\n";
	else cout<<"YES\n";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    char s[105][105];
    cin>>n>>m;
    for(int i=0; i<n; ++i)
        cin>>s[i];
    for(int i=0; i<n; ++i)
    {
        int te=s[i][0];  //取每行的第一个
        if(te==s[i+1][0]) //与下一行第一个进行比较
        {
            cout<<"NO"<<endl;
            goto bye;   //使用goto语句跳出，比较方便
        }
        for(int j=1; j<m; ++j)
        {
            if(te!=s[i][j]) //与每行的其他元素进行比较
            {
                cout<<"NO"<<endl;
                goto bye;
            }
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[110][110];
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(i!=n-1&&a[i][0]==a[i+1][0]){
			cout<<"NO";
			return 0;
		}
		for(int j=0;j<m;j++){
			if(a[i][j]!=a[i][0]){
				cout<<"NO";
				return 0;
			}
		}
	}
	cout<<"YES";
	return 0;
}


#include<stdio.h>
char t, l;
int n, m;
int main(){
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i){
        getchar();
        t = getchar();
        if (t == l){
            printf("NO");
            return 0;
        }
        l = t;
        for (int j = 1; j < n; ++j){
            t = getchar();
            if (t != l){
                printf("NO");
                return 0;
            }
            l = t;
        }
    }
    printf("YES");
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,m;
	string s[120];
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n-1;j++)
		{
			if((s[i][j]-'0')!=(s[i][j+1]-'0'))
			{
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}
	for(int i=0;i<n-1;i++)
	{
		if((s[i][0]-'0')==(s[i+1][0]-'0'))
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	if(n>=10)
	{
		cout<<"NO"<<endl;
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
char c[110][110];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		scanf("%s",c[i]+1);
	char now='*';
	bool flag=true;
	for(int i=1;i<=n;i++)
	{
		if(now==c[i][1])
		{
			flag=false;
			break;
		}
		now=c[i][1];
		for(int j=1;j<=m;j++)
			if(c[i][j]!=now)
			{
				flag=false;
				goto exiter;
			}
	}
	exiter:;
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}
//


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
int n,m;
char ch[110][110];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>ch[i][j];
	 for(int i=1;i<=n;i++)
	 {
	 	for(int j=1;j<=m;j++)
	 	{
	 		if(ch[i][j]!=ch[i][j-1]&&j!=1){cout<<"NO";return 0;}
	 		if(ch[i][j]==ch[i-1][j]&&i!=1){cout<<"NO";return 0;}
	 	}
	 }
	 cout<<"YES";
return 0;
}


#include<cstdio>
using namespace std;
int n,m;
char f,last=' ';
{
    scanf("%d%d",&n,&m);
    for(register int i=1;i<=n;i++)
    {
        f=getchar();
        while(f<'0'||f>'9')  f=getchar();
        for(register int j=2;j<=m;j++)
        {
            char t=getchar();
            if(t!=f) {printf("NO");return 0;}
        }
        if(last==f){printf("NO");return 0;}
        last=f;
    }
    printf("YES");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m;
char s[60][60];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",&s[i]);
		if(i!=0&&s[i][0]==s[i-1][0]){
			printf("NO\n");
			return 0;
		}
		for(int j=1;j<m;j++){
			if(s[i][j]!=s[i][j-1]){
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
	return 0;
}


#include<cstdio>
using namespace std;
int n,m;
char f,last=' ';
int main()
{
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;i++)
	{
		f=getchar();
		while(f<'0'||f>'9')  f=getchar();
		for(register int j=2;j<=m;j++)
		{
			char t=getchar();
			if(t!=f) {printf("NO");return 0;}
		}
		if(last==f){printf("NO");return 0;}
		last=f;
	}
	printf("YES");
	return 0;
}


#include<iostream>
#include<string>
using namespace std;

const int MAX_N = 101;
const int MAX_M = 101;
char a[MAX_N][MAX_M] = {0};

int main(){
	int n, m;
	cin >> n >> m;
	int flag = 0;

	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			cin >> a[i][j];
			if(j > 1 && a[i][j] != a[i][j-1])
			{
				flag = -1;
			}
		}
		if(i > 1 && a[i][1] == a[i-1][1])
		    flag = -1;
	}
	if(flag == 0) cout << "YES";
	else cout << "NO";

}


#include <bits/stdc++.h>

using namespace std;

int main () {
	int n, m;
	scanf("%d%d", &n, &m);
	int flag[10086][10086];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			scanf("%d", &flag[i][j]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			for (int k = 1; k <= j; k++)
				if (flag[i][j] != flag[i][k]) {
					printf("NO");
					return 0;
				}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++)
			if (flag[i][1] == flag[j][1]) {
				printf("NO");
				return 0;
			}
	printf("YES");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

	cout<<"YES";
}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m;
    char s,a[101][101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        scanf("%s",a[i]);
        s=a[i][0];
        for(int j=1;j<m;j++)
        if(a[i][j]!=s){cout<<"NO";return 0;}
        if(strcmp(a[i],a[i-1])==0&&i!=0)
        {cout<<"NO";return 0;}
    }
    cout<<"YES";
    return 0;
}


#include<iostream>
using namespace std;
char a[100][100];
main()
{
	int n,m;
	bool flag=true;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(int i=0;i<n;i++)
	{
		char gog=a[i][0];
		for(int j=1;j<m;j++)
		{
			if(gog!=a[i][j])flag=false;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++){
		if(a[i][j]==a[i+1][j])
		flag=false;}
	}
	if(!flag)cout<<"NO\n";
	else cout<<"YES\n";
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
bool work(string a){
    for (int i=0;i<a.size()-1;i++)
        if (a[i]!=a[i+1]) return 0;
    return 1;
}
int main(){
    cin>>n>>m;
    for (int i=1;i<=n;i++){
        char x;
        string y;
        cin>>y;
        if (!work(y)){ cout<<"NO"; return 0;}
        if (i==1){ x=y[0]; continue;}
        if (x==y[0]){ cout<<"NO"; return 0;}
        x=y[0];
    }
    cout<<"YES";
    return 0;
}


#include<iostream>
using namespace std;
int n,m;
char flag[110][110];
int main(){
    cin>>n>>m;
    for(int i=0;i<n;++i){
        cin>>flag[i];
    for(int i=0;i<n;++i){
        if(i!=n-1&&flag[i][0]==flag[i+1][0]){
            cout<<"NO";
            return 0;
        }
        for(int j=0;j<m;++j)
            if(flag[i][j]!=flag[i][0]){
                cout<<"NO";
                return 0;
            }
    }
    cout<<"YES";
    return 0;


#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(){
	int n,m;
	int flag=0;
	string a,p,q;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a;
		if(i==1){
			p=a[0];
		}
		else{
			q=a[0];
			if(q==p){
				flag=1;
			}
			p=q;
		}
		for(int i=0;i<m-1;i++){
			if(a[i]!=a[i+1]){
				flag=1;
			}
		}
	}
	if(flag){
		cout<<"NO"<<endl;
	}
	else{
		cout<<"YES"<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int n,m;char flag[110][110];
int main(){
    cin>>n>>m;
    for(int i=0;i<n;++i){
        cin>>flag[i];
    }for(int i=0;i<n;++i){
        if(i!=n-1&&flag[i][0]==flag[i+1][0]){
            cout<<"NO";return 0;
        }for(int j=0;j<m;++j){
            if(flag[i][j]!=flag[i][0]){
                cout<<"NO";return 0;
            }
        }
    }
    cout<<"YES";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,m;

    cin >> n >> m;
    char a[n][m],tmp;
    for(int i = 0; i<n; i++){
    	for(int j = 0; j<m; j++){
			cin >> a[i][j];
			if(j==0) tmp = a[i][j];
    		if(a[i][j]!=tmp){
    			cout << "NO";
    			return 0;
			}
		}
		if(i!=0&&a[i][0]==a[i-1][0]){
			cout << "NO";
			return 0;
		}
		getchar();
	}
	cout << "YES";
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int N = 100 + 7;

int n, m;
char a[N][N];

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		scanf("%s", a[i] + 1);
		for (int j = 2; j <= n; ++j)
			if (a[i][j - 1] != a[i][j]) return printf("NO"), 0;
		if (a[i][1] == a[i - 1][1]) return printf("NO"), 0;
	}
	printf("YES");
	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=110;
char mapp[MAXN][MAXN];
int n,m;
bool color(int i)
{
	for(register int j=1;j<m;j++)
	{
		if(mapp[i][j]!=mapp[i][j+1]) return false;
	}
	return true;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;i++)
		for(register int j=1;j<=m;j++)
			cin>>mapp[i][j];
    for(register int i=1;i<=n;i++)
	{
		if(color(i)==0)
		{
			puts("NO");
			return 0;
		}
		if(i!=n)
		{
			if(mapp[i][1]==mapp[i+1][1])
			{
				puts("NO");
				return 0;
			}
		}
	}
	puts("YES");

}


#include <bits/stdc++.h>
using namespace std;
int n,m;
char ch[101][101];
int main()
{
	cin >> n >> m;
	for (int i = 1;i <= n;i++)
	    for (int j = 1;j <= m;j++)
	    {
	    	cin >> ch[i][j];
			if (j != 1 && ch[i][j] != ch[i][j - 1])
			    puts ("NO"),exit(0);
		}
	puts ("YES");
	return 0;
}


#include<cstdio>
using namespace std;
int n,m;
char f,last=' ';
int main()
{
    scanf("%d%d",&n,&m);
    for(register int i=1;i<=n;i++)
    {
        f=getchar();
        while(f<'0'||f>'9')  f=getchar();
        for(register int j=2;j<=m;j++)
        {
            char t=getchar();
            if(t!=f) {printf("NO");return 0;}
        }
        if(last==f){printf("NO");return 0;}
        last=f;
    }
    printf("YES");
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char arr[n][n];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>arr[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(j!=0)
            {
                if(arr[i][0]!=arr[i][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
                if(arr[i][j]==arr[i+1][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char arr[n][m];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>arr[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(j!=0)
            {
                if(arr[i][0]!=arr[i][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
        }
    }

    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<m;j++)
        {
                if(arr[i][j]==arr[i+1][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char arr[n][n];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>arr[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(j!=0)
            {
                if(arr[i][0]!=arr[i][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
        }
    }

    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<m;j++)
        {
                if(arr[i][j]==arr[i+1][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char arr[n][n];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>arr[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(j!=0)
            {
                if(arr[i][0]!=arr[i][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i!=0)
            {
                if(arr[0][j]==arr[i][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char arr[n][m];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>arr[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(j!=0)
            {
                if(arr[i][0]!=arr[i][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
                if(arr[i][j]==arr[i+1][j])
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


#include <bits//stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define MAX 1000000
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define in scanf
#define pf printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}

//Split String by Single Character Delimiter
vector<string> split(const string& s, char delim)
{
    vector<string> elems;
    stringstream ss(s);
    string item;

    while (getline(ss, item, delim))
        elems.push_back(item);

    return elems;
}
// this function goes to main for splitting
//vector<string> words;
//words = split("lorem_ipsum_dolor_sit_amet_no_tota_tacimates_delicata_eum", '_');
//for(int i=0; i<words.size(); i++)
//cout << words.at(i) << endl;

//sort with respect to the second element in a pair !!
//bool comp(const pair<int, int>&i, const pair<int, int>&j) {
//        return i.second < j.second;
//}
//vector< pair<int, int> >v;
//sort(v.begin(), v.end(), comp);

const int dr [] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc [] = {0, 1, 1, 1, 0, -1, -1, -1};

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int i32;
typedef unsigned long int ui32;
typedef long long int i64;
typedef unsigned long long int  ui64;

const int T2=105; const int T3=1005; const int T4=10005; const int T5=100005;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    string a[110];
    cin >> n >> m;
    REP(i, n) cin >> a[i];

    REP(i, n){
        REP(j, m-1){
            if(a[i][j] != a[i][j+1]){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    REP(i, n){
        REP(j, m-1){
            if(a[j][i] == a[j+1][i]){
                cout << "NO" << endl;
                return 0;
            }
        }
    }

    cout << "YES" << endl;
    return 0;
}


#include <bits//stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define MAX 1000000
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define in scanf
#define pf printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}

//Split String by Single Character Delimiter
vector<string> split(const string& s, char delim)
{
    vector<string> elems;
    stringstream ss(s);
    string item;

    while (getline(ss, item, delim))
        elems.push_back(item);

    return elems;
}
// this function goes to main for splitting
//vector<string> words;
//words = split("lorem_ipsum_dolor_sit_amet_no_tota_tacimates_delicata_eum", '_');
//for(int i=0; i<words.size(); i++)
//cout << words.at(i) << endl;

//sort with respect to the second element in a pair !!
//bool comp(const pair<int, int>&i, const pair<int, int>&j) {
//        return i.second < j.second;
//}
//vector< pair<int, int> >v;
//sort(v.begin(), v.end(), comp);

const int dr [] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc [] = {0, 1, 1, 1, 0, -1, -1, -1};

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int i32;
typedef unsigned long int ui32;
typedef long long int i64;
typedef unsigned long long int  ui64;

const int T2=105; const int T3=1005; const int T4=10005; const int T5=100005;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    string a[110];
    cin >> n >> m;
    REP(i, n) cin >> a[i];

    REP(i, n){
        REP(j, m-1){
            if(a[i][j] != a[i][j+1]){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    REP(i, n-1){
        REP(j, m-1){
            if(a[j][i] == a[j+1][i]){
                cout << "NO" << endl;
                cout << "x" <<i << " " << j <<endl;
                return 0;
            //cout << i << " " << j <<" ";
           }
        }
    }

    cout << "YES" << endl;
    return 0;
}


#include <bits//stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define MAX 1000000
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define in scanf
#define pf printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}

//Split String by Single Character Delimiter
vector<string> split(const string& s, char delim)
{
    vector<string> elems;
    stringstream ss(s);
    string item;

    while (getline(ss, item, delim))
        elems.push_back(item);

    return elems;
}
// this function goes to main for splitting
//vector<string> words;
//words = split("lorem_ipsum_dolor_sit_amet_no_tota_tacimates_delicata_eum", '_');
//for(int i=0; i<words.size(); i++)
//cout << words.at(i) << endl;

//sort with respect to the second element in a pair !!
//bool comp(const pair<int, int>&i, const pair<int, int>&j) {
//        return i.second < j.second;
//}
//vector< pair<int, int> >v;
//sort(v.begin(), v.end(), comp);

const int dr [] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc [] = {0, 1, 1, 1, 0, -1, -1, -1};

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int i32;
typedef unsigned long int ui32;
typedef long long int i64;
typedef unsigned long long int  ui64;

const int T2=105; const int T3=1005; const int T4=10005; const int T5=100005;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    string a[110];
    cin >> n >> m;
    REP(i, n) cin >> a[i];

    REP(i, n){
        REP(j, m-1){
            if(a[i][j] != a[i][j+1]){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    for(int i=1; i<n; i++) {
        if(a[i] == a[i-1]) {
             cout << "NO" << endl;
                return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}


#include <bits//stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define MAX 1000000
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define in scanf
#define pf printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}

//Split String by Single Character Delimiter
vector<string> split(const string& s, char delim)
{
    vector<string> elems;
    stringstream ss(s);
    string item;

    while (getline(ss, item, delim))
        elems.push_back(item);

    return elems;
}
// this function goes to main for splitting
//vector<string> words;
//words = split("lorem_ipsum_dolor_sit_amet_no_tota_tacimates_delicata_eum", '_');
//for(int i=0; i<words.size(); i++)
//cout << words.at(i) << endl;

//sort with respect to the second element in a pair !!
//bool comp(const pair<int, int>&i, const pair<int, int>&j) {
//        return i.second < j.second;
//}
//vector< pair<int, int> >v;
//sort(v.begin(), v.end(), comp);

const int dr [] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc [] = {0, 1, 1, 1, 0, -1, -1, -1};

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int i32;
typedef unsigned long int ui32;
typedef long long int i64;
typedef unsigned long long int  ui64;

const int T2=105; const int T3=1005; const int T4=10005; const int T5=100005;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    string a[110];
    cin >> n >> m;
    REP(i, n) cin >> a[i];

    REP(i, n){
        REP(j, m-1){
            if(a[i][j] != a[i][j+1]){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    REP(i, n-1){
        REP(j, m-1){
            if(a[j][i] == a[j+1][i]){
                cout << "NO" << endl;
                return 0;
           }
        }
    }

    cout << "YES" << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m,f=1,i,j;
    cin>>n>>m;
    char a[101],b;
    for(i=0;i<n;++i)
    {  cin>>a;
    if(i>0 && a[0]==b) f=0;
    b=a[0];
        for(j=1;a[j]!=0;++j)
        {
           if(b!=a[j]) f=0;
        }
    }
    if(f==0)cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m,a,b,f=1,i,j;
    cin>>n>>m;
    for(i=0;i<n;++i)
    {  cin>>a;
        for(j=1;j<m;++j)
        {
           cin>>b;
           if(b!=a) f=0;
        }
    }
    if(f==0)cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m,f=1,i,j;
    cin>>n>>m;
    char a[41],b;
    for(i=0;i<n;++i)
    {  cin>>a;
    b=a[0];
        for(j=1;a[j]!=0;++j)
        {
           if(b!=a[j]) f=0;
        }
    }
    if(f==0)cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m,f=1,i,j;
    cin>>n>>m;
    char a[41],b;
    for(i=0;i<n;++i)
    {  cin>>a;
    if(i>0 && a[0]==b) f=0;
    b=a[0];
        for(j=1;a[j]!=0;++j)
        {
           if(b!=a[j]) f=0;
        }
    }
    if(f==0)cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	bool flag=false;
	int size=0,counter=0,colur=0,row,colum;
	char previous=-1;
char arr[100][100];
cin>>row>>colum;

for(int i=0;i<row;i++)
{
	for(int j=0 ;j<colum;j++)
	{
		cin>>arr[i][j];
	}
}

while(size!=colum)
{
for(int k=0 ;k<colum;k++)
{
	if(previous!=arr[size][k] &&arr[size][0]==arr[size][k])
	{
		counter++;
	}
	if(counter==colum)
	{
		colur++;
	}
	if(k==colum-1)
	{
		counter=0;
		previous=arr[size][0];
		size++;
	}
}
}
 if(colur==colum)
	cout<<"YES"<<endl;
else
	cout<<"NO"<<endl;

}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int row,colum,num,counter=1,counter1=1,c=0;;
	bool color=true;
	vector<vector<int>>flag;
	vector<int>f;
	cin>>row>>colum;
	for(int i=0 ;i<row;i++)
	{
		for(int j=0 ;j<colum;j++)
	{
		cin>>num;
		f.push_back(num);
	}
		flag.push_back(f);

		f.clear();
	}

int cop=flag[0][0];
int cop2=cop;
int i2=0;
int a=0;
		for(int j=1 ;j<colum;j++)
	{
		if(flag[i2][j]==cop)
		{
		counter++;
		}
		if(counter==colum && i2!=colum-1)
		{
			i2++;
		j=0;
		cop=flag[i2][j];
		counter=1;

		}
		else if(flag[i2][j]!=cop)
		{
			cout<<"NO";
			color=false;
			break;
		}

		}
		if(color==true)
		c++;
		for(int k=1 ;k<row;k++)
	{
		if(flag[k][a]==cop2)
		{
			cout<<"NO";
			color=false;
			break;
		}
		else if(flag[k][a]!=cop2)
		{
		counter1++;
		cop2=flag[k][a];

		}
		if(counter1==row && a!=row-1)
		{
			a++;
			k=1;
			cop2=flag[0][k];
			k--;
			counter1=1;

		}
}
		if(color==true)
		c++;
		if(c==2)
		{
			cout<<"YES";
		}

}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int row,colum,num,counter=1,counter1=1,c=0;;
	bool color=true;
	vector<vector <int> >flag;
	vector<int>f;
	cin>>row>>colum;
	for(int i=0 ;i<row;i++)
	{
		for(int j=0 ;j<colum;j++)
	{
		cin>>num;
		f.push_back(num);
	}
		flag.push_back(f);

		f.clear();
	}

int cop=flag[0][0];
int cop2=cop;
int i2=0;
int a=0;
		for(int j=1 ;j<colum;j++)
	{
		if(flag[i2][j]==cop)
		{
		counter++;
		}
		if(counter==colum && i2!=colum-1)
		{
			i2++;
		j=0;
		cop=flag[i2][j];
		counter=1;

		}
		else if(flag[i2][j]!=cop)
		{

			color=false;
			break;
		}

		}
		if(color==true)
		c++;
		for(int k=1 ;k<row;k++)
	{
		if(flag[k][a]==cop2)
		{
			cout<<"NO";
			color=false;
			break;
		}
		else if(flag[k][a]!=cop2)
		{
		counter1++;
		cop2=flag[k][a];

		}
		if(counter1==row && a!=row-1)
		{
			a++;
			k=1;
			cop2=flag[0][k];
			k--;
			counter1=1;

		}
}
		if(color==true)
		c++;
		if(c==2)
		{
			cout<<"YES";
		}

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	bool flag=false;
	int size=0,counter=0,colur=0,row,colum;
	char previous=-1;
char arr[100][100];
cin>>row>>colum;

for(int i=0;i<row;i++)
{
	for(int j=0 ;j<colum;j++)
	{
		cin>>arr[i][j];
	}
}

while(size!=row)
{
for(int k=0 ;k<colum;k++)
{
	if(previous!=arr[size][k] &&arr[size][0]==arr[size][k])
	{
		counter++;
	}
	if(counter==colum)
	{
		colur++;
	}
	if(k==colum-1)
	{
		counter=0;
		previous=arr[size][0];
		size++;
	}
}
}
if(row==1 && colur==1)
	cout<<"YES";
 else if(colur==row)
	cout<<"YES"<<endl;
else
	cout<<"NO"<<endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	bool flag=false;
	int size=0,counter=1,colur=0,row,colum;
	char previous=-1;
char arr[100][100];
cin>>row>>colum;

for(int i=0;i<row;i++)
{
	for(int j=0 ;j<colum;j++)
	{
		cin>>arr[i][j];
	}
}

while(size!=colum)
{
for(int k=1 ;k<colum;k++)
{
	if(previous!=arr[size][k] &&arr[size][0]==arr[size][k])
	{
		counter++;
	}
	if(counter==colum)
	{
		colur++;
	}
	if(k==colum-1)
	{
		counter=1;
		previous=arr[size][0];
		size++;
	}
}
}
if(colur==row)
	cout<<"YES"<<endl;
else
	cout<<"NO"<<endl;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	bool flag=false;
	int size=0,counter=1,colur=0,row,colum;
	char previous=-1;
char arr[100][100];
cin>>row>>colum;

for(int i=0;i<row;i++)
{
	for(int j=0 ;j<colum;j++)
	{
		cin>>arr[i][j];
	}
}

while(size!=colum)
{
for(int k=1 ;k<colum;k++)
{
	if(previous!=arr[size][k] &&arr[size][0]==arr[size][k])
	{
		counter++;
	}
	if(counter==colum)
	{
		colur++;
	}
	if(k==colum-1)
	{
		counter=1;
		previous=arr[size][0];
		size++;
	}
}
}
if(colur==colum)
	cout<<"YES"<<endl;
else
	cout<<"NO"<<endl;

}


#include <bits/stdc++.h>
using namespace std;

char find(int a[], int b){
	int d = 0;
	for(int i = 0 ; i < sizeof(a) / sizeof(a[0]) ; i++)
		if(a[i] == b)
			d++;
	return d;
}

int main() {

	int n, m, fsatr = 0, fsoton = 0;
	cin >> n >> m;
	int satr[m];
	int soton[n];
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			int a;
			if(j == 0)
				cin >> a;
			satr[j] = a % 10;
			a /= 10;
			if(j == 0)
				soton[i] = satr[0];
			if(j > 0){
				if(satr[j] != satr[j - 1])
					fsatr = 1;
			}
		}
	}
	for(int i = 0 ; i < n ; i++)
		if(find(soton, soton[i]) >= 2)
			fsoton = 1;
	if(fsatr == 1 || fsoton == 1)
		cout << "NO";
	else
		cout << "YES";
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int n, m, flag_satr = 0, flag_soton = 0;

int main() {
	cin >> n >> m;
	int check_satr[m], check_soton[n];

	for(int i = 0 ; i < n ; i++){
		int num;
		cin >> num;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = num % 10;
			num /= 10 ;
			check_soton[i] = check_satr[0];
			if(j > 0 && check_satr[j] != check_satr[j - 1]){
				flag_satr = 1;
				break;
			}
			if(i > 0 && check_soton[i] == check_soton[i - 1]){
				flag_soton = 1;
				break;
			}
		}
		if(flag_satr == 1)
			break;
		if(flag_soton == 1)
			break;
	}
	if(flag_satr == 1 || flag_soton == 1)
		cout << "NO";
	else
		cout << "YES";
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int n, m, flag_satr = 0, flag_soton = 0;

bool find(int a[], int b){
	int d = 0;
	for(int i = 0 ; i < n ; i++){
		if(a[i] == b)
			d++;
	}
	if(d > 1)
		return false;
	else
		return true;
}

int main() {
	cin >> n >> m;
	int check_satr[m], check_soton[n];

	for(int i = 0 ; i < n ; i++){
		int num;
		cin >> num;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = num % 10;
			num /= 10 ;
			check_soton[i] = check_satr[0];
			if(j > 0 && check_satr[j] != check_satr[j - 1]){
				flag_satr = 1;
				break;
			}
			if(i > 0 && check_soton[i] != check_soton[i - 1]){
				flag_soton = 1;
				break;
			}
		}
		if(flag_satr == 1)
			break;
		if(flag_soton == 1)
			break;
	}
	if(flag_satr == 1 || flag_soton == 1)
		cout << "NO";
	else{
		cout << "YES";
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int n, m, flag_satr = 0, flag_soton = 0;

bool find(int a[], int b){
	int d = 0;
	for(int i = 0 ; i < n ; i++){
		if(a[i] == b)
			d++;
	}
	if(d > 1)
		return false;
	else
		return true;
}

int main() {
	cin >> n >> m;
	int check_satr[m], check_soton[n];

	for(int i = 0 ; i < n ; i++){
		int num;
		cin >> num;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = num % 10;
			num /= 10;
			check_soton[i] = check_satr[0];
			if(j > 0 && check_satr[j] != check_satr[j - 1]){
				flag_satr = 1;
				break;
			}
		}
		if(flag_satr == 1)
			break;
	}
	if(flag_satr == 1)
		cout << "NO";
	else{
		for(int i = 0 ; i < n ; i++){
			if(find(check_soton, check_soton[i]) == false ){
				flag_soton = 1;
				break;
			}
		}
		if(flag_soton == 1)
			cout << "NO";
		else
			cout << "YES";
	}
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int find(int arr[], int a){
	int b = 0;
	for(int i = 0 ; i < sizeof(arr) - sizeof(arr[0]) ; i++)
		if(arr[i] == a)
			b++;
	return b;
}

int main() {
	int n, m;
	bool flag_satr = true, flag_soton = true;
	cin >> n >> m;
	int check_satr[m];
	int check_soton[n];

	for(int i = 0 ; i < n ; i++){
		string a;
		cin >> a;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = a[j];
			check_soton[i] = a[0];
			if(j > 1){
				if(check_satr[j] != check_satr[j - 1])
					flag_satr = false;
			}
		}
	}
	if(flag_satr == false)
		cout << "NO";
	else{
		for(int i = 0 ; i < n ; i++)
			if(find(check_soton, check_soton[i]) > 1){
				flag_soton = false;
				break;
			}
		if(flag_soton == false)
			cout << "NO";
		else
			cout << "YES";
	}
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int n, m, flag_satr = 0, flag_soton = 0;

int main() {
	cin >> n >> m;
	int check_satr[m], check_soton[n];

	for(int i = 0 ; i < n ; i++){
		int f = 0;
		string num;
		cin >> num;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = num[f] - '0';
			check_soton[i] = check_satr[0];
			if(j > 0 && check_satr[j] != check_satr[j - 1]){
				flag_satr = 1;
				break;
			}
			if(i > 0 && check_soton[i] == check_soton[i - 1]){
				flag_soton = 1;
				break;
			}
			f++;
		}
		if(flag_satr == 1)
			break;
		if(flag_soton == 1)
			break;
	}
	if(flag_satr == 1 || flag_soton == 1)
		cout << "NO";
	else
		cout << "YES";
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int n, m, flag_satr = 0, flag_soton = 0;

int main() {
	cin >> n >> m;
	int check_satr[m], check_soton[n];

	for(int i = 0 ; i < n ; i++){
		int f = 0;
		string num;
		cin >> num;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = num[f] - '0';
			check_soton[i] = check_satr[0];
			if(j > 0 && check_satr[j] != check_satr[j - 1]){
				flag_satr = 1;
				break;
			}
			if(i > 0 && check_soton[i] == check_soton[i - 1]){
				flag_soton = 1;
				break;
			}
		}
		if(flag_satr == 1)
			break;
		if(flag_soton == 1)
			break;
	}
	if(flag_satr == 1 || flag_soton == 1)
		cout << "NO";
	else
		cout << "YES";
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int find(int arr[], int a){
	int b = 0;
	for(int i = 0 ; i < sizeof(arr) - sizeof(arr[0]) ; i++)
		if(arr[i] == a)
			b++;
	return b;
}

int main() {
	int n, m;
	bool flag_satr = true, flag_soton = true;
	cin >> n >> m;
	int check_satr[m];
	int check_soton[n];

	for(int i = 0 ; i < n ; i++){
		string a;
		cin >> a;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = a[j];
			check_soton[i] = a[0];
			if(j > 1){
				if(check_satr[j] != check_satr[j - 1])
					flag_satr = false;
			}
		}
	}
	if(flag_satr == false)
		cout << "NO";
	else{
		for(int i = 0 ; i < n ; i++){
			/*cout << check_soton[i] << " " << find(check_soton, check_soton[i]) << endl;*/
			if(find(check_soton, check_soton[i]) > 1){
				flag_soton = false;
				break;
			}
		}
		if(flag_soton == false)
			cout << "NO";
		else
			cout << "YES";
	}
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int find(int arr[], int a){
	int b = 0;
	for(int i = 0 ; i < sizeof(arr) - sizeof(arr[0]) ; i++)
		if(arr[i] == a)
			b++;
	return b;
}

int n, m;
bool flag_satr = true, flag_soton = true;

int main() {
	cin >> n >> m;
	int check_satr[m];
	int check_soton[n];
	for(int i = 0 ; i < n ; i++){
		string a;
		cin >> a;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = a[j];
			check_soton[i] = a[0];
			if(j > 1){
				if(check_satr[j] != check_satr[j - 1])
					flag_satr = false;
			}
		}
	}
	if(flag_satr == false)
		cout << "NO" << endl;

	else{
		for(int i = 0 ; i < n ; i++){
			/*cout << check_soton[i] << " " << find(check_soton, check_soton[i]) << endl;*/
			if(find(check_soton, check_soton[i]) > 1){
				flag_soton = false;
				break;
			}
		}
		if(flag_soton == false)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int n, m, flag_satr = 0, flag_soton = 0;

bool find(int a[], int b){
	int d = 0;
	for(int i = 0 ; i < n ; i++){
		if(a[i] == b)
			d++;
	}
	if(d > 1)
		return false;
	else
		return true;
}

int main() {
	cin >> n >> m;
	int check_satr[m], check_soton[n];

	for(int i = 0 ; i < n ; i++){
		int num;
		cin >> num;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = num % 10;
			num /= 10 ;
			check_soton[i] = check_satr[0];
			if(j > 0 && check_satr[j] != check_satr[j - 1]){
				flag_satr = 1;
				break;
			}
		}
		if(flag_satr == 1)
			break;
	}
	if(flag_satr == 1)
		cout << "NO";
	else{
		for(int i = 0 ; i < n ; i++){
			if(find(check_soton, check_soton[i]) == false ){
				flag_soton = 1;
				break;
			}
		}
		if(flag_soton == 1)
			cout << "NO";
		else
			cout << "YES";
	}
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int find(int arr[], int a){
	int b = 0;
	for(int i = 0 ; i < sizeof(arr) - sizeof(arr[0]) ; i++)
		if(arr[i] == a)
			b++;
	return b;
}

int main() {
	int n, m;
	bool flag_satr = true, flag_soton = true;
	cin >> n >> m;
	int check_satr[m];
	int check_soton[n];

	for(int i = 0 ; i < n ; i++){
		string a;
		cin >> a;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = a[j];
			check_soton[i] = a[0];
			if(j > 1){
				if(check_satr[j] != check_satr[j - 1])
					flag_satr = false;
			}
		}
	}
	if(flag_satr == false)
		cout << "NO" << endl;

	else{
		for(int i = 0 ; i < n ; i++){
			/*cout << check_soton[i] << " " << find(check_soton, check_soton[i]) << endl;*/
			if(find(check_soton, check_soton[i]) > 1){
				flag_soton = false;
				break;
			}
		}
		if(flag_soton == false)
			cout << "NO" << endl;
		else
			cout << "YES" <<  endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

int find(int arr[], int a){
	int b = 0;
	for(int i = 0 ; i < sizeof(arr) - sizeof(arr[0]) ; i++)
		if(arr[i] == a)
			b++;
	return b;
}

int main() {
	int n, m;
	bool flag_satr = true, flag_soton = true;
	cin >> n >> m;
	int check_satr[m];
	int check_soton[n];

	for(int i = 0 ; i < n ; i++){
		string a;
		cin >> a;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = a[j];
			check_soton[i] = a[0];
			if(j > 1){
				if(check_satr[j] != check_satr[j - 1])
					flag_satr = false;
			}
		}
	}
	if(flag_satr == false)
		cout << "NO";

	else{
		for(int i = 0 ; i < n ; i++){
			/*cout << check_soton[i] << " " << find(check_soton, check_soton[i]) << endl;*/
			if(find(check_soton, check_soton[i]) > 1){
				flag_soton = false;
				break;
			}
		}
		if(flag_soton == false)
			cout << "NO";
		else
			cout << "YES";
	}
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int n, m, flag_satr = 0, flag_soton = 0;

int main() {
	cin >> n >> m;
	int check_satr[m], check_soton[n];

	for(int i = 0 ; i < n ; i++){
		int f = 0;
		string num;
		cin >> num;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = num[f] - '0';
			check_soton[i] = check_satr[0];
			if(j > 0 && check_satr[j] != check_satr[j - 1]){
				flag_satr = 1;
				break;
			}
			if(i > 0 && check_soton[i] == check_soton[i - 1]){
				cout << "HALOOO";
				flag_soton = 1;
				break;
			}
		}
		if(flag_satr == 1)
			break;
		if(flag_soton == 1)
			break;
	}
	if(flag_satr == 1 || flag_soton == 1)
		cout << "NO";
	else
		cout << "YES";
}


#include <bits/stdc++.h>
using namespace std;

int find(int a[], int b){
	int d = 0;
	for(int i = 0 ; i < sizeof(a) / sizeof(a[0]) + 1 ; i++){
		/*cout << a[i] << " " << b << " " << d << endl;*/
		if(a[i] == b)
			d++;
	}
	return d;
}

int main() {

	int n, m, fsatr = 0, fsoton = 0;
	cin >> n >> m;
	int satr[m];
	int soton[n];
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			int a;
			if(j == 0)
				cin >> a;
			satr[j] = a % 10;
			a /= 10;
			if(j == 0)
				soton[i] = satr[0];
			if(j > 0){
				if(satr[j] != satr[j - 1])
					fsatr = 1;
			}
		}
	}
	/*for(int i = 0 ; i < n ; i++)
		cout << soton[i];
	cout << endl;*/
	for(int i = 0 ; i < n ; i++){
		/*cout << soton[i] << " " << find(soton, soton[i]) << endl;*/
		if(find(soton, soton[i]) >= 2){
			fsoton = 1;

		}
	}
	if(fsatr == 1 || fsoton == 1)
		cout << "NO";
	if(fsatr == 0 && fsoton == 0)
		cout << "YES";
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int find(int arr[], int a){
	int b = 0;
	for(int i = 0 ; i < sizeof(arr) - sizeof(arr[0]) ; i++)
		if(arr[i] == a)
			b++;
	return b;
}

int main() {
	int n, m;
	bool flag_satr = true, flag_soton = true;
	cin >> n >> m;
	int check_satr[m];
	int check_soton[n];

	for(int i = 0 ; i < n ; i++){
		string a;
		cin >> a;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = a[j];
			check_soton[i] = a[0];
			if(j > 1){
				if(check_satr[j] != check_satr[j - 1])
					flag_satr = false;
			}
		}
	}
	if(flag_satr == false)
		cout << "NO" << endl;

	else{
		for(int i = 0 ; i < n ; i++){
			/*cout << check_soton[i] << " " << find(check_soton, check_soton[i]) << endl;*/
			if(find(check_soton, check_soton[i]) > 1){
				flag_soton = false;
				break;
			}
		}
		if(flag_soton == false)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;;
	}
}


#include <bits/stdc++.h>
#include <string>
using namespace std;

int find(int arr[], int a){
	int b = 0;
	for(int i = 0 ; i < sizeof(arr) - sizeof(arr[0]) ; i++)
		if(arr[i] == a)
			b++;
	return b;
}

int main() {
	int n, m;
	bool flag_satr = true, flag_soton = true;
	cin >> n >> m;
	int check_satr[m];
	int check_soton[n];

	for(int i = 0 ; i < n ; i++){
		string a;
		cin >> a;
		for(int j = 0 ; j < m ; j++){
			check_satr[j] = a[j];
			check_soton[i] = a[0];
			if(j > 1){
				if(check_satr[j] != check_satr[j - 1])
					flag_satr = false;
			}
		}
	}
	if(flag_satr == false)
		cout << "NO" << endl;

	else{
		for(int i = 0 ; i < n ; i++){
			/*cout << check_soton[i] << " " << find(check_soton, check_soton[i]) << endl;*/
			if(find(check_soton, check_soton[i]) > 1){
				flag_soton = false;
				break;
			}
		}
		if(flag_soton == false)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
}


/*#include <stdio.h>

#include<string.h>

int main()
{
    int b,n,c,m,i,temp,d,e,j,max1,sum[55];
     char a[55][55],k=0;
       scanf("%d %d",&n,&m);
        for(i=0;i<n;i++){
        scanf("%s",&a[i]);

        for(j=0;j<m-1;j++){
           if(a[i][j]!=a[i][j+1]){ k=1;break;} }
            if(a[i][j]==a[i+1][j])k=1; }

      for(i=0;i<n-1;i++) {if(a[i][j]==a[i+1][j])k=1;break;}
     if(k==0)printf("YES\n");else if(k==1){printf("NO\n");}
    return 0;
}*/#include<iostream>
using namespace std;
int n,m;//旗帜的长和宽
char flag[110][110];//存旗帜每个点
int main(){
    cin>>n>>m;
    for(int i=0;i<n;++i){//一重循环，每次输入一行
        cin>>flag[i];
    }
    for(int i=0;i<n;++i){//循环每一行
        if(i!=n-1&&flag[i][0]==flag[i+1][0]){
            cout<<"NO";//如果这不是最后一行且它和下一行开头一样
            return 0;//直接结束，免得输出多个结果，下同
        }
        for(int j=0;j<m;++j){
            if(flag[i][j]!=flag[i][0]){//如果某一行出现了多种颜色
                cout<<"NO";
                return 0;
            }
        }
    }
    cout<<"YES";//此时的旗帜一定是合格的
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m;
    char s,a[101][101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        scanf("%s",a[i]);
        s=a[i][0];
        for(int j=1;j<m;j++)
        if(a[i][j]!=s){cout<<"NO";return 0;}
        if(strcmp(a[i],a[i-1])==0&&i!=0)
        {cout<<"NO";return 0;}
    }
    cout<<"YES";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[120][120];
int main()
{
    int n,m;
    char ch;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
     for (int j=1;j<=m;j++)
      {
         cin>>ch;
         a[i][j]=ch-48;
      }
    for (int i=1;i<=n;i++)
     if (a[i][1]==a[i+1][1] && i!=n) {cout<<"NO";return 0;}
     else
    {
       for (int j=1;j<=m;j++)
        if (a[i][j]!=a[i][j+1] && j!=m) {cout<<"NO";return 0;}
    }
    cout<<"YES";
    return 0;
}


#include<cstdio>
#include<cstring>
int n,m,len,s;
char c[105],flag[105];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//  ios::sync_with_stdio(false);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",c);
		len=strlen(c)-1;
		flag[i]=c[0];
		if(i>1&&flag[i]==flag[i-1]){printf("NO\n");return 0;}
		for(int j=1;j<=len;++j)
			if(c[j]!=flag[i]){printf("NO\n");return 0;}
	}
	printf("YES\n");
	return 0;
}


#include <cstdio>
#include <iostream>
#define F "NO\n"
#define T "YES\n"
int a[110][110],n,m;
char temp;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			std::cin>>temp,a[i][j]=temp-'0';
	for(int i=1;i<=n;i++){
		bool flag=1;
		for(int j=2;j<=m;j++)
			if(a[i][j]!=a[i][j-1]){
				flag=0; break;
			}
		if(!flag) {printf(F); return 0;}
	}
	for(int i=2;i<=n;i++){
		if(a[i][1]==a[i-1][1]) { printf(F); return 0;}
	}
	printf(T);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m;
char ch[101][101];
int main()
{
	cin >> n >> m;
	for (int i = 1;i <= n;i++)
	    for (int j = 1;j <= m;j++)
	    {
	    	cin >> ch[i][j];
			if (j != 1 && ch[i][j] != ch[i][j - 1] || i != 1 && ch[i][j] == ch[i - 1][j])
			    puts ("NO"),exit(0);
		}
	puts ("YES");
	return 0;
}


#include<stdio.h>
int hash[100005];
int main()
{
	int n,x,i,y,ans,a,b;
	scanf("%d %d",&n,&x);
	for(i=0;i<10000;i++)
	hash[i]=0;
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&a,&b);
		hash[a]=hash[a]+b;
	}
	ans=0;
	y=x;
	if(hash[1]>=y)
	{
		ans=ans+y;
		hash[1]=hash[1]-y;
	}
	else
	{
		ans=ans+hash[1];
		hash[1]=0;
	}
	//printf("%d %d\n ",hash[1],ans);
	for(i=2;i<=10000;i++)
	{
		//printf("%d ",ans);
		y=x;
		if(hash[i-1]!=0)
		{
			if(hash[i-1]>=y)
			{
				hash[i-1]=hash[i-1]-y;
				ans=ans+y;
				y=0;
			}
			else
			{
				y=y-hash[i-1];
				ans=ans+hash[i-1];
				hash[i-1]=0;
			}
		}
		//printf("%d ",ans);
		if(y!=0 && hash[i]!=0)
		{
			if(hash[i]>=y)
			{
				hash[i]=hash[i]-y;
				ans=ans+y;
				y=0;
			}
			else
			{
				ans=ans+hash[i];
				y=y-hash[i];
				hash[i]=0;
			}
		}
		//printf("%d ",ans);
	}
	printf("%d",ans);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
long n,v,d[3005]={0},m=0;
int main()
{
	long i,a,b,l0=0,l1=0,ans=0,vv;
	scanf("%ld %ld",&n,&v);
	for (i=1;i<=n;i++)
	{
		scanf("%ld %ld",&a,&b);
		d[a]+=b;
		if (a>m) m=a;
	}
	m++;
	for (i=1;i<=m;i++)
	{
		l0=l1;
		l1=d[i];
		if (l0>=v) ans+=v;
		else
		{
			ans+=l0;
			vv=v-l0;
			if (vv>=l1)
			{
				ans+=l1;
				l1=0;
			}
			else
			{
				l1-=vv;
				ans+=vv;
			}
		}
	}
	printf("%ld",ans);
	return 0;
}