#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define S0RT(a,n) sort(a, a + n)
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);

/* NOTES TO SELF:
    Int overflow? Use all ll if in doubt.
    Edge cases? (n = 1, n = 0)
*/

int n, m;
char f[102][102];

int main(){
    IOS;
    cin >> n >> m;
    F0R(i,n){
        F0R(j,m){
            cin >> f[j][i];
        }
    }
    char prevColor;
    char currColor;
    F0R(i,n){
        currColor = f[0][i];
        if(i > 0){
            if(currColor == prevColor){
                cout << "NO";
                return 0;
            }
        }
        F0R(j,m){
            if(f[j][i] != currColor){
                cout << "NO";
                return 0;
            }
        }
        prevColor = currColor;
    }
    cout << "YES";
    return 0;
}


#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define S0RT(a,n) sort(a, a + n)
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);

/* NOTES TO SELF:
    Int overflow? Use all ll if in doubt.
    Edge cases? (n = 1, n = 0)
*/

int n, m;
int f[102][102];

int main(){
    IOS;
    cin >> n >> m;
    F0R(i,n){
        F0R(j,m){
            cin >> f[j][i];
        }
    }
    int prevColor;
    int currColor;
    F0R(i,n){
        currColor = f[i][0];
        if(i > 0){
            if(currColor == prevColor){
                cout << "NO";
                return 0;
            }
        }
        F0R(j,m){
            if(f[j][i] != currColor){
                cout << "NO";
                return 0;
            }
        }
        prevColor = currColor;
    }
    cout << "YES";
    return 0;
}


#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define S0RT(a,n) sort(a, a + n)
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);

/* NOTES TO SELF:
    Int overflow? Use all ll if in doubt.
    Edge cases? (n = 1, n = 0)
*/

int n, m;
int f[102][102];

int main(){
    IOS;
    cin >> n >> m;
    F0R(i,n){
        F0R(j,m){
            cin >> f[j][i];
        }
    }
    int prevColor;
    int currColor;
    F0R(i,n){
        currColor = f[i][0];
        if(currColor == prevColor){
            cout << "NO";
            return 0;
        }
        F0R(j,m){
            if(f[j][i] != currColor){
                cout << "NO";
                return 0;
            }
        }
        prevColor = currColor;
    }
    cout << "YES";
    return 0;
}


#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define S0RT(a,n) sort(a, a + n)
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);

/* NOTES TO SELF:
    Int overflow? Use all ll if in doubt.
    Edge cases? (n = 1, n = 0)
*/

int n, m;
int f[102][102];

int main(){
    IOS;
    cin >> n >> m;
    F0R(i,n){
        F0R(j,m){
            cin >> f[j][i];
        }
    }
    int prevColor;
    int currColor;
    F0R(i,n){
        currColor = f[0][i];
        if(i > 0){
            if(currColor == prevColor){
                cout << "NO";
                return 0;
            }
        }
        F0R(j,m){
            if(f[j][i] != currColor){
                cout << "NO" << j << " " << i;
                return 0;
            }
        }
        prevColor = currColor;
    }
    cout << "YES";
    return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[1000][1000];
	bool b=true;
	cin>>n;cin>>m;

		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){

			if(m>1)for(int j=0;j<=m-2;j++){
			         if((v[i][j] != v[i][j+1])){b=false;}
			       }}

		for(int i=2;i<=n;i++){
				if((v[i][0]==v[i-1][0]))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[1000][1000];
	bool b=true;
	cin>>n;cin>>m;

		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){
			if(m>1)
			for(int j=1;j<=m;j++){
			if((v[i][j] != v[i][j+1])and(j+1 !=m)){b=false;}
			}
				if((v[i][1]==v[i+1][1])and(i+1 !=n))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[1000][1000];
	bool b=true;
	cin>>n;cin>>m;

		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){

			if(m>1)for(int j=0;j<=m-1;j++){
			         if((v[i][j] != v[i][j+1])and(j+2 !=m)){b=false;}
			       }}
		for(int i=2;i<=n;i++){
				if((v[i][0]==v[i-1][0]))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[1000][1000];
	bool b=true;
	cin>>n;cin>>m;

		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){

			if(m>1)for(int j=0;j<=m-1;j++){
			         if((v[i][j] != v[i][j+1])and(j+2 !=m)){b=false;}
			       }

				if((v[i][0]==v[i+1][0])and(i+1 !=n))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[100][100];
	bool b=true;
	cin>>n;cin>>m;

		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if((v[i][j] != v[i][j+1])and(j+1 !=m)){b=false;}
			}
				if((v[i][1]==v[i+1][1])and(i+1 !=n))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[1000][1000];
	bool b=true;
	cin>>n;cin>>m;

		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){

			if(m>1)for(int j=0;j<=m-1;j++){
			         if((v[i][j] != v[i][j+1])and(j+2 !=m)){b=false;}
			       }

				if((v[i][0]==v[i-1][0]))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[100][100];
	bool b=true;
	cin>>n;cin>>m;

	if(n==m){
		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if((v[i][j] != v[i][j+1])and(j+1 !=m)){if(b)cout<<v[i][j]<<" "<<v[i][j+1];b=false;}
			}
				if((v[i][1]==v[i+1][1])and(i+1 !=n))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";
	}

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[100][100];
	bool b=true;
	cin>>n;cin>>m;

	if(n==m){
		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if((v[i][j] != v[i][j+1])and(j+1 !=m)){b=false;}
			}
				if((v[i][1]==v[i+1][1])and(i+1 !=n))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";
	}

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[1000][1000];
	bool b=true;
	cin>>n;cin>>m;

		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=2;i<=n;i++){

			if(m>1)for(int j=1;j<=m;j++){
			         if((v[i][j] != v[i][j+1])and(j+1 !=m)){b=false;}
			       }

				if((v[i][0]==v[i-1][0]))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";

return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n,m;
	char v[1000][1000];
	bool b=true;
	cin>>n;cin>>m;

		for(int i=1;i<=n;i++)
		     cin>>v[i];

		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if((v[i][j] != v[i][j+1])and(j+1 !=m)){b=false;}
			}
				if((v[i][1]==v[i+1][1])and(i+1 !=n))b=false;
		}
		if(b==true){cout<<"YES" ;}else cout<<"NO";

return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
    int n,m,r[500],c[500];
    string rd;
    vector<string>vc;
    scanf("%d %d",&n,&m);
    getchar();
    int x;
    for(int i=0;i<n;i++){
        cin>>rd;
        vc.push_back(rd);
    }
    int cnt=0,cnt2=0;
    for(int i=0;i<n;i++){
        cnt=0;
        for(int j=0;j<m;j++){
            if(vc[i][0]==vc[i][j]){
                cnt++;
            }
        }
        if(cnt!=m){
            printf("NO\n");
            return 0;
        }
        else {
            cnt2++;
        }

    }
    if(cnt2!=n){
        printf("NO\n");
        return 0;
    }
    for(int i=0;i<m;i++){
        cnt=0;
        for(int j=0;j<n;j++){
            if(vc[0][i]==vc[j][i]){
                cnt++;
            }
        }
        if(cnt>1){
            printf("NO\n");
            return 0;
        }
    }

    printf("YES\n");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
    int n,m,r[500],c[500];
    string rd;
    vector<string>vc;
    scanf("%d %d",&n,&m);
    getchar();
    int x;
    for(int i=0;i<n;i++){
        cin>>rd;
        vc.push_back(rd);
    }
    int cnt=0,cnt2=0;
    for(int i=0;i<n;i++){
        cnt=0;
        for(int j=0;j<m;j++){
            if(vc[i][0]==vc[i][j]){
                cnt++;
            }
        }
        if(cnt!=m){
            printf("NO\n");
            return 0;
        }
        else {
            cnt2++;
        }

    }
    if(cnt2!=n){
        printf("NO\n");
        return 0;
    }
    cnt=0;
    for(int i=0;i<n-1;i++){
        if(vc[i]==vc[i+1]){
            printf("NO\n");
            return 0;
        }
    }

    printf("YES\n");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
    int n,m,r[500],c[500];
    string rd;
    vector<string>vc;
    scanf("%d %d",&n,&m);
    getchar();
    int x;
    for(int i=0;i<n;i++){
        cin>>rd;
        vc.push_back(rd);
    }
    int cnt=0,cnt2=0;
    for(int i=0;i<n;i++){
        cnt=0;
        for(int j=0;j<m;j++){
            if(vc[i][0]==vc[i][j]){
                cnt++;
            }
        }
        if(cnt!=m){
            printf("NO\n");
            return 0;
        }
        else {
            cnt2++;
        }

    }
    if(cnt2!=n){
        printf("NO\n");
        return 0;
    }
    cnt=0;
    for(int i=0;i<m-1;i++){
        if(vc[i]==vc[i+1]){
            printf("NO\n");
            return 0;
        }
    }

    printf("YES\n");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
    int n,m,r[500],c[500];
    string rd;
    vector<string>vc;
    scanf("%d %d",&n,&m);
    getchar();
    int x;
    for(int i=0;i<n;i++){
        cin>>rd;
        vc.push_back(rd);
    }
    int cnt=0,cnt2=0;
    for(int i=0;i<n;i++){
        cnt=0;
        for(int j=0;j<m;j++){
            if(vc[i][0]==vc[i][j]){
                cnt++;
            }
        }
        if(cnt!=m){
            printf("NO\n");
            return 0;
        }
        else {
            cnt2++;
        }

    }
    if(cnt2!=n){
        printf("NO\n");
        return 0;
    }
    /**for(int i=0;i<m;i++){
        cnt=0;
        for(int j=0;j<n;j++){
            if(vc[0][i]==vc[j][i]){
                cnt++;
            }
        }
        if(cnt>1){
            printf("NO\n");
            return 0;
        }
    }
    **/

    printf("YES\n");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    bool flag=true;
    for(int i=0;i<n;i++)
    {
        char c;
        cin>>c;
        for(int j=1;j<m;j++)
        {
            char d;
            cin>>d;
            if(d!=c)
            {
                flag=false;
                i=n;
                j=m;
            }
        }
    }
    if(flag==true)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    bool flag=true;
    set<char>s;
    for(int i=0;i<n;i++)
    {
        char c;
        cin>>c;
        for(int j=1;j<m;j++)
        {
            char d;
            cin>>d;
            if(d!=c)
            {
                flag=false;
            }
        }
        s.insert(c);
    }
    if(flag==true && s.size()==n)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    bool flag=true;
    for(int i=0;i<n;i++)
    {
        char c;
        for(int j=1;j<m;j++)
        {
            char d;
            cin>>d;
            if(d!=c)
            {
                flag=false;
                i=n;
                j=m;
            }
        }
    }
    if(flag==true)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    bool flag=true;
    set<char>s;
    for(int i=0;i<n;i++)
    {
        char c;
        cin>>c;
        for(int j=1;j<m;j++)
        {
            char d;
            cin>>d;
            if(d!=c)
            {
                flag=false;
                i=n;
                j=m;
            }
        }
        s.insert(c);
    }
    if(flag==true && s.size()==n)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


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


#include <iostream>
#include <stdio.h>
using namespace std;
int main ()
{
int n;
int m = 0;
scanf("%i%i", &n, &m);
int ios[100][100];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
            {{
                scanf("%1d", &ios[i][j]);

            }}
        for (int i = 0; i < n - 1; i++)
            for (int j = 0; j < m; j++)
            {{
                if(ios[i][j] == ios[i + 1][j])
                {
                    printf("NO");
                }}
        }

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

}


#include <iostream>
#include <stdio.h>
using namespace std;
int main ()
{
int n, m = 0;
cin >> n,m;
int iso[100][100];
    for (int i = 1; i < n; i++)
        for (int j = 0; j < m; j++)
    {{
    cin >> iso[i][j];

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

                }}

        for (int i = 0; i < n; i++)
            for (int j = 0; j < m - 1; j++)
            {{
                if(iso[i][j] != iso[i][j + 1])
                {
                   cout << "NO";

                }}
        }
            goto result;
            }
            result:
        cout << "YES" <<endl;
        return 0;
    }


#include <iostream>
#include <stdio.h>
using namespace std;
int main ()
{
int n;
int m = 0;
scanf("%i%i", &n, &m);
int ios[100][100];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
            {{
                scanf("%1d", &ios[i][j]);

            }}
        for (int i = 0; i < n - 1; i++)
            for (int j = 0; j < m; j++)
            {{
                if(ios[i][j] == ios[i + 1][j])
                {
                    printf("NO");
                    return 0;
                }}
        }

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

}


#include <iostream>
#include <stdio.h>
using namespace std;
int main ()
{
int n, m = 0;
cin >> n,m;
int iso[100][100];
    for (int i = 1; i < n; i++)
        for (int j = 0; j < m; j++)
    {{
    cin >> iso[i][j];

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

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


#include <stdio.h>
using namespace std;
int main ()
{
int n, m = 0;
cin >> n,m;
int iso[100][100];
    for (int i = 1; i < n; i++)
        for (int j = 0; j < m; j++)
    {{
    cin >> iso[i][j];

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

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


#include <iostream>
using namespace std;

int main()
{
    //Declaring Variables
    int n, m;
    cin >> n; cin >> m;

    char pre, str, temp;
    cin >> pre;
    str = pre;

    for(int k = 0; k < m - 1; ++k)
    {
        cin >> temp;
        if(temp!=str)
        {
            printf("NO");
            return 0;
        }
    }

    for(int i = 1; i < n; ++i)
    {
        cin >> str;
        for(int j = 0; j < m - 1; ++j)
        {
            cin >> temp;
            if(temp!=str || temp == pre)
            {
                printf("NO");
                return 0;
            }
        }
    }

    printf("YES");
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n, m;
    cin >> n; cin >> m;

    char pre, str, temp;
    cin >> pre;
    str = pre;

    for(int k = 0; k < m - 1; ++k)
    {
        cin >> temp;
        if(temp!=str)
        {
            printf("NO");
            return 0;
        }
    }

    for(int i = 1; i < n; ++i)
    {
        cin >> str;
        for(int j = 0; j < m - 1; ++j)
        {
            cin >> temp;
            if(temp!=str || temp == pre)
            {
                printf("NO");
                return 0;
            }
        }
    }

    printf("YES");
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    //n is the number of rows and m is the number of colums
    int n, m;
    cin >> n; cin >> m;

    char previous, actual, temp;
    //previous is the previousvious row color
    //actual is the actual row color
    //temp is the char we get as input

    //Getting previous and actual for the first row
    cin >> previous;
    actual = previous;

    //This for checks every color from the first row
    for(int k = 0; k < m - 1; ++k)
    {
        cin >> temp;

        //If there is found a different color the program ends
        if(temp!=actual)
        {
            printf("NO");
            return 0;
        }
    }

    //This for goes from the second row to the last one
    for(int i = 1; i < n; ++i)
    {
        //Getting the actual color from this row
        cin >> actual;

        //This for checks every color from this row
        for(int j = 0; j < m - 1; ++j)
        {
            cin >> temp;

            /*If there is found a different color
            or the color is similar to the previous row the program ends*/
            if(temp!=actual || temp == previous)
            {
                printf("NO");
                return 0;
            }
        }
        //Asign to previous the actual color
        previous = actual;
    }

    //If te program has not ended yet this means that the flag is correct
    printf("YES");
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    //Declaring Variables
    int n, m;
    cin >> n; cin >> m;

    char pre, str, temp;
    cin >> pre;
    str = pre;

    for(int k = 0; k < m - 1; ++k)
    {
        cin >> temp;
        if(temp!=str)
        {
            printf("NO");
            return 0;
        }
    }

    for(int i = 1; i < n; ++i)
    {
        cin >> str;
        for(int j = 0; j < m - 1; ++j)
        {
            cin >> temp;
            if(temp!=str || temp == pre)
            {
                printf("NO");
                return 0;
            }
        }
        pre = temp;
    }

    printf("YES");
    return 0;
}


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

#define LL long long int

bool isDiff(string str)
{
    for(int i = 0; i < str.length()-1; i++)
    {
        if(str[i] == str[i+1])
            return false;
    }
    return true;
}

int main()
{
    int r, c;
    cin >> r >> c;

    char grid[r][c];

    char ch;

    for(int i = 0; i < r; i++)
    {
        set <char> St;
        for(int j = 0; j < c; j++)
        {
            cin >> grid[i][j];
            St.insert(grid[i][j]);
        }
        if(St.size() != 1)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    for (int j = 0; j < r; j++)
    {
        string str = "";

        for (int i = 0; i < c; i++)
        {
            str += grid[i][j];
        }
        if(isDiff(str) == false)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}


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

#define LL long long int

bool isDiff(string str)
{
    for(int i = 0; i < str.length()-1; i++)
    {
        if(str[i] == str[i+1])
            return false;
    }
    return true;
}

int main()
{
    int r, c;
    cin >> r >> c;

    char grid[r][c];

    char ch;

    for(int i = 0; i < r; i++)
    {
        set <char> St;
        for(int j = 0; j < c; j++)
        {
            cin >> grid[i][j];
            St.insert(grid[i][j]);
        }
        if(St.size() != 1)
        {
            cout << "NO" << endl;
            return 0;
        }

        if(r == 1)
        {
            string ans;
            St.size() == 1 ? ans = "YES" : ans = "NO";
            cout << ans << endl;
            return 0;
        }
    }

    for (int j = 0; j < r; j++)
    {
        string str = "";

        for (int i = 0; i < c; i++)
        {
            str += grid[i][j];
        }
        if(isDiff(str) == false)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}


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

#define LL long long int

bool isSame(string str, int len)
{
    set <char> St;

    for(int i = 0; i < str.length(); i++)
    {
        St.insert(str[i]);
    }

    return St.size() == len;
}

int main()
{
    int r, c;
    cin >> r >> c;

    char grid[r][c];

    char ch;

    for(int i = 0; i < r; i++)
    {
        for(int j = 0; j < c; j++)
        {
            cin >> grid[i][j];
        }
    }

    for (int i = 0; i < r; i++)
    {
        string str = "";
        for (int j = 0; j < c; j++)
        {
            str += grid[i][j];
        }

        if(isSame(str, 1) == false)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    for (int j = 0; j < r; j++)
    {
        string str = "";

        for (int i = 0; i < c; i++)
        {
            str += grid[i][j];
        }
        if(isSame(str, str.size()) == false)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}


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

#define LL long long int

int main()
{
    int N, M;
    cin >> N >> M;

    vector <string> V(N);

    for(int i = 0; i < N; i++)
    {
        cin >> V[i];
    }

    for(int i = 0; i < N; i++)
    {
        char ch = V[i][0];

        for(int j = 0; j < M; j++)
        {
            if(V[i][j] != ch) return cout << "NO" << endl, 0;
        }
        if(i > 0)
        {
            if(V[i][0] == V[i-1][0]) return cout << "NO" << endl, 0;
        }
    }
    return cout << "YES" << endl, 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool arr[26];

int main() {

	for (size_t i = 0; i < 26; i++)
		arr[i] = 0;
	bool flag = false;
	int n, m;
	cin >> n >> m;
	vector < string > s(n);
	vector<char> a;
	for (size_t i = 0; i < s.size(); i++) {
		cin >> s[i];
		a.push_back(s[i][0]);

	}

	for (size_t i = 0; i < a.size() - 1; i++){
		if (a[i] == a[i + 1])
			flag = 1;
	}

	for (size_t i = 0; i < m; i++){

		sort(s[i].begin(), s[i].end());
		if (s[i][0] != s[i][s[i].size() - 1]) {
			flag = 1;
			break;
		}
	}
	if (flag) {
		cout << "NO" << endl;
//		system("pause");
		return 0;
	}

	cout << "YES" << endl;
//	system("pause");
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool arr[26];

int main() {

	for (size_t i = 0; i < 26; i++)
		arr[i] = 0;
	bool flag = false;
	int n, m;
	cin >> n >> m;
	vector < string > s(n);
	vector<int> a(n);
	for (size_t i = 0; i < s.size(); i++) {
		cin >> s[i];
		a.push_back(s[i][0]);
	}

	for (size_t i = 0; i < a.size() - 1; i++){
		if (a[i] == a[i + 1])
			flag = 1;
	}

	for (size_t i = 0; i < m; i++){

		sort(s[i].begin(), s[i].end());
		if (s[i][0] != s[i][s[i].size() - 1]) {
			flag = 1;
			break;
		}
	}
	if (flag) {
		cout << "NO" << endl;
//		system("pause");
		return 0;
	}

	cout << "YES" << endl;
//	system("pause");
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool arr[26];

int main() {

	for (size_t i = 0; i < 26; i++)
		arr[i] = 0;
	bool flag = false;
	int n, m;
	cin >> n >> m;
	vector < string > s(n);
	for (size_t i = 0; i < s.size(); i++) {
		cin >> s[i];
		if (!arr[s[i][0] - 'a'])
			arr[s[i][0] - 'a'] = 1;
		else
			flag = 1;
	}

	for (size_t i = 0; i < s.size(); i++){
		sort(s[i].begin(), s[i].end());
		if (s[i][0] != s[i][i])
			break;
	}
	if (flag) {
		cout << "NO" << endl;
//		system("pause");
		return 0;
	}

	cout << "YES" << endl;
//	system("pause");
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool arr[26];

int main() {

	for (size_t i = 0; i < 26; i++)
		arr[i] = 0;
	bool flag = false;
	int n, m;
	cin >> n >> m;
	vector < string > s(n);
	vector<char> a;
	for (size_t i = 0; i < s.size(); i++) {
		cin >> s[i];
		a.push_back(s[i][0]);

	}

	for (size_t i = 0; i < a.size() - 1; i++){
		if (a[i] == a[i + 1])
			flag = 1;
	}

	for (size_t i = 0; i < n; i++){
		for (size_t j = 0; j < m - 1; j++)
		{
			if (s[i][j] != s[i][j + 1])
				flag = 1;
		}
	}
	if (flag) {
		cout << "NO" << endl;
//		system("pause");
		return 0;
	}

	cout << "YES" << endl;
//	system("pause");
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool arr[26];

int main() {

	for (size_t i = 0; i < 26; i++)
		arr[i] = 0;
	bool flag = false;
	int n, m;
	cin >> n >> m;
	vector < string > s(n);
	for (size_t i = 0; i < s.size(); i++) {
		cin >> s[i];
	}
	if (n == 2) {
		if (s[0][0] == s[1][0])
			flag = 1;
	}

	for (size_t i = 0; i < s.size(); i++){
		if (i > 0 && i < s.size() - 1) {
			if (s[i][0] == s[i + 1][0] || s[i - 1][0] == s[i][0])
				flag = 1;
		}
		sort(s[i].begin(), s[i].end());
		if (s[i][0] != s[i][i]) {
			flag = 1;
			break;
		}
	}
	if (flag) {
		cout << "NO" << endl;
//		system("pause");
		return 0;
	}

	cout << "YES" << endl;
//	system("pause");
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool arr[26];

int main() {

	for (size_t i = 0; i < 26; i++)
		arr[i] = 0;
	bool flag = false;
	int n, m;
	cin >> n >> m;
	vector < string > s(n);
	for (size_t i = 0; i < s.size(); i++)
		cin >> s[i];

	for (size_t i = 0; i < m - 1; i++){
		if (s[i][0] == s[i + 1][0])
			flag = 1;
	}

	for (size_t i = 0; i < m; i++){

		sort(s[i].begin(), s[i].end());
		if (s[i][0] != s[i][s[i].size() - 1]) {
			flag = 1;
			break;
		}
	}
	if (flag) {
		cout << "NO" << endl;
//		system("pause");
		return 0;
	}

	cout << "YES" << endl;
//	system("pause");
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool arr[26];

int main() {

	for (size_t i = 0; i < 26; i++)
		arr[i] = 0;
	bool flag = false;
	int n, m;
	cin >> n >> m;
	vector < string > s(n);
	for (size_t i = 0; i < s.size(); i++) {
		cin >> s[i];
	}
	if (n == 2) {
		if (s[0][0] == s[1][0])
			flag = 1;
	}

	for (size_t i = 0; i < s[i].size(); i++){
		if (i < s.size() - 1) {
			if (s[i][0] == s[i + 1][0])
				flag = 1;
		}
		sort(s[i].begin(), s[i].end());
		if (s[i][0] != s[i][s[i].size() - 1]) {
			//cout << s[i][0] << "    " << s[i][s[i].size() - 1] << endl;
			flag = 1;
			break;
		}
	}
	if (flag) {
		cout << "NO" << endl;
//		system("pause");
		return 0;
	}

	cout << "YES" << endl;
//	system("pause");
}


/*
   AUTHOR :- Gaurang_Kothiya

   Quote:-" Great things never come from comfort zones."
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map
#define u_m(a,b) unordered_map
#define mm(a,b) multimap
#define s(a) set
#define us(a) unordered_set
#define ms(a) multiset
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

void Solve()
{
	int n,m;
	cin>>n>>m;
	char a[n][m];
	f(i,0,n-1)

	if(n==1)
	{
		cout<<"YES";
		return ;

	}
	f(i,0,n-1)
	{
		f(j,0,m-1) cin>>a[i][j];
	}
	f(i,0,n-2)
	{
		s(char) s1,s2;
		f(j,0,m-1) s1.insert(a[i][j]);
		f(j,0,m-1) s2.insert(a[i+1][j]);
		if(s1.sz==s2.sz && s1.sz==1 && *s1.B != *s2.B);
		else
		{
			cout<<"NO";
			return;
		}
	}
	cout<<"YES";
}

signed main()
{
	speed

	int q=1;
	//cin>>q;

	while(q--)
	Solve();

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


/*
   AUTHOR :- Gaurang_Kothiya

   Quote:-" Great things never come from comfort zones."
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map
#define u_m(a,b) unordered_map
#define mm(a,b) multimap
#define s(a) set
#define us(a) unordered_set
#define ms(a) multiset
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

void Solve()
{
	int n,m;
	cin>>n>>m;
	char a[n][m];
	f(i,0,n-1)

	if(n==1)
	{
		cout<<"YES";
		return ;

	}

	{
		f(j,0,m-1) cin>>a[i][j];
	}
	f(i,0,n-2)
	{
		s(char) s1,s2;
		f(j,0,m-1) s1.insert(a[i][j]);
		f(j,0,m-1) s2.insert(a[i+1][j]);
		if(s1.sz==s2.sz && s1.sz==1 && *s1.B != *s2.B);
		else
		{
			cout<<"NO";
			return;
		}
	}
	cout<<"YES";
}

signed main()
{
	speed

	int q=1;
	//cin>>q;

	while(q--)
	Solve();

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


/*
   AUTHOR :- Gaurang_Kothiya

   Quote:-" Great things never come from comfort zones."
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map
#define u_m(a,b) unordered_map
#define mm(a,b) multimap
#define s(a) set
#define us(a) unordered_set
#define ms(a) multiset
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

void Solve()
{
	int n,m;
	cin>>n>>m;
	char a[n][m];
	f(i,0,n-1)
	{
		f(j,0,m-1) cin>>a[i][j];
	}
	f(i,0,n-2)
	{
		s(char) s1,s2;
		f(j,0,m-1) s1.insert(a[i][j]);
		f(j,0,m-1) s2.insert(a[i+1][j]);
		if(s1.sz==s2.sz && s1.sz==1 && *s1.B != *s2.B);
		else
		{
			cout<<"NO";
			return;
		}
	}
	cout<<"YES";
}

signed main()
{
	speed

	int q=1;
	//cin>>q;

	while(q--)
	Solve();

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


/*
   AUTHOR :- Gaurang_Kothiya

   Quote:-" Great things never come from comfort zones."
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map
#define u_m(a,b) unordered_map
#define mm(a,b) multimap
#define s(a) set
#define us(a) unordered_set
#define ms(a) multiset
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

void Solve()
{
	int n,m;
	cin>>n>>m;
	char a[n][m];
	f(i,0,n-1)

	if(n==1)
	{
		cout<<"NO";
		return ;

	}
	f(i,0,n-1)
	{
		f(j,0,m-1) cin>>a[i][j];
	}
	f(i,0,n-2)
	{
		s(char) s1,s2;
		f(j,0,m-1) s1.insert(a[i][j]);
		f(j,0,m-1) s2.insert(a[i+1][j]);
		if(s1.sz==s2.sz && s1.sz==1 && *s1.B != *s2.B);
		else
		{
			cout<<"NO";
			return;
		}
	}
	cout<<"YES";
}

signed main()
{
	speed

	int q=1;
	//cin>>q;

	while(q--)
	Solve();

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


/*
   AUTHOR :- Gaurang_Kothiya

   Quote:-" Great things never come from comfort zones."
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map
#define u_m(a,b) unordered_map
#define mm(a,b) multimap
#define s(a) set
#define us(a) unordered_set
#define ms(a) multiset
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

void Solve()
{
	int n,m;
	cin>>n>>m;
	char a[n][m];
	f(i,0,n-1)

	f(i,0,n-1)
	{
		f(j,0,m-1) cin>>a[i][j];
	}

	if(n==1)
	{
		s(char) s1;
		f(i,0,m-1) s1.insert(a[0][i]);
		if(s1.sz==1) cout<<"YES";
		else cout<<"NO";
		return ;

	}

	f(i,0,n-2)
	{
		s(char) s1,s2;
		f(j,0,m-1) s1.insert(a[i][j]);
		f(j,0,m-1) s2.insert(a[i+1][j]);
		if(s1.sz==s2.sz && s1.sz==1 && *s1.B != *s2.B);
		else
		{
			cout<<"NO";
			return;
		}
	}
	cout<<"YES";
}

signed main()
{
	speed

	int q=1;
	//cin>>q;

	while(q--)
	Solve();

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


/*
   AUTHOR :- Gaurang_Kothiya

   Quote:-" Great things never come from comfort zones."
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map
#define u_m(a,b) unordered_map
#define mm(a,b) multimap
#define s(a) set
#define us(a) unordered_set
#define ms(a) multiset
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

void Solve()
{
	int n,m;
	cin>>n>>m;
	char a[n][m];
	f(i,0,n-1)

	if(n==1)
	{
		s(char) s1;
		f(i,0,m-1) s1.insert(a[0][i]);
		if(s1.sz==1) cout<<"YES";
		else cout<<"NO";
		return ;

	}
	f(i,0,n-1)
	{
		f(j,0,m-1) cin>>a[i][j];
	}
	f(i,0,n-2)
	{
		s(char) s1,s2;
		f(j,0,m-1) s1.insert(a[i][j]);
		f(j,0,m-1) s2.insert(a[i+1][j]);
		if(s1.sz==s2.sz && s1.sz==1 && *s1.B != *s2.B);
		else
		{
			cout<<"NO";
			return;
		}
	}
	cout<<"YES";
}

signed main()
{
	speed

	int q=1;
	//cin>>q;

	while(q--)
	Solve();

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


#include <iostream>
using namespace std ;
int main(){
int n,m;
bool t=1;
char arr[100][100];
cin>>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(arr[i][j]==arr[i+1][j])
    {
        t=1;
        break;

    }
    }
        }
        for (int i=0;i<n;i++){
        for(int j=0;j<m;j++){
    if(arr[i][j]==arr[i][j-1]){
        t=1;
        break;
    }
        }
        if (t==0) {cout<<"YES";
goto finish;
        }

else {cout<<"NO";
goto finish;
}

        }

finish:
return 0;
        }


#include <iostream>
using namespace std;

int main(){
    int n, m;
    bool k=1;
    char a[100][100];
    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=1; j<m; ++j){
            if(a[i][j]!=a[i][j-1]){
                k=0;
                break;
            }
        }
    }

    for (int i=0; i<n; ++i){
        for (int j=0; j<m; ++j){
            if(a[i][j]==a[i+1][j]){
                k=0;
                break;
            }
        }
    }
    if(k==1)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
int n,m;
bool x;
x=1;
cin>>n>>m;
char a[100][100];
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=1;j<m;j++){
    if (a[i][j]!=a[i+1][j]&&a[i][j]==a[i][j-1]){
        x=0;
    }
    else {x=1;}
    }

}

if (x==0){
cout<<"YES";}
else{cout<<"NO";}

return 0;}


#include <iostream>
using namespace std;
int main(){
int n,m;
bool t;
t=1;
cin>>n>>m;
char a[100][100];
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=1;j<m;j++){
    if (a[i][j]!=a[i+1][j]&&a[i][j]==a[i][j-1]){
        t=0;
    }
    else {t=1;}
    }

}

if (t==0){
cout<<"YES";}
else{cout<<"NO";}

return 0;}


#include <iostream>
using namespace std ;
int main(){
int n,m,s=0;
char arr[100][100];
cin>>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(arr[i][j]==arr[i+1][j])
    {
        s=1;

    }
    }
        for (int i=0;i<n;i++){
        for(int j=0;j<m;j++){
    if(arr[i][j]==arr[i][j+1])
    {
        s=0;
    }
        }
        if (s=1) {cout<<"YES";
        goto finish;
        }

else {cout<<"NO";
goto finish;
}

        }
        }

finish:

return 0;
        }


#include <iostream>
using namespace std ;
int main(){
int n,m;
bool t=1;
char arr[100][100];
cin>>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(arr[i][j]==arr[i+1][j])
    {
        t=1;
        break;

    }
    }
        }
        for (int i=0;i<n;i++){
        for(int j=0;j<m;j++){
    if(arr[i][j]==arr[i][j-1]){
        t=1;
        break;
    }
        }
        if (t==0) {cout<<"YES";
goto finish;
        }

else {cout<<"NO";
goto finish;
}

        }


#include <iostream>
using namespace std ;
int main(){
int n,m,s=0;
char arr[100][100];
cin>>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(arr[i][j]==arr[i+1][j])
    {
        s=1;

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

else {cout<<"NO";
goto finish;
}

        }
        }

finish:

return 0;
        }


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

int main()
{
    int i,j,k,n,m,sum=0,l=0,rating=0,rating2=0,rating3=0;
    cin>>n>>m;
    string str,str1;

    for(i=0;i<n;i++)
    {
        cin>>str;

        for(j=0;j<str.length();j++)
        {
            if(str[j]>='0'&&str[j]<='9')
                rating2++;
            for(k=1;k<str.length()-1;k++)
            {
                if(str[j]==str[k])
                    sum++;
            }
        }
        if(sum==m)
        {
            rating++;
        }
        sum=0;

        if(i>=1)
        {
            if(str.length()==str1.length())
                rating3++;
            if(str1==str)
                l++;
        }
        str1=str;
    }

    if(rating!=m||l>=1||rating2<n*m||rating3<m-1)
      cout<<"NO"<<endl;
    else if(rating==m&&rating2==n*m&&rating3>=m-1)
         cout<<"YES"<<endl;

    return 0;
}


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

int main()
{
    int i,j,k,n,m,sum=0,l=0,rating=0,rating2=0,rating3=0;
    cin>>n>>m;
    string str,str1;

    for(i=0;i<n;i++)
    {
        cin>>str;

        for(j=0;j<str.length();j++)
        {
            if(str[j]>='0'&&str[j]<='9')
                rating2++;
            for(k=1;k<str.length()-1;k++)
            {
                if(str[j]==str[k])
                    sum++;
            }
        }
        if(sum==m)
        {
            rating++;
        }
        sum=0;

        if(i>=1)
        {
            if(str.length()==str1.length())
                rating3++;
            if(str1==str)
                l++;
        }
        str1=str;
    }

    if(rating!=m||l>=1||rating2<n*m||rating3<2)
      cout<<"NO"<<endl;
    else
         cout<<"YES"<<endl;

    return 0;
}


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

int main()
{
    int i,j,k,n,m,sum=0,l=0,rating=0,rating2=0;
    cin>>n>>m;
    string str,str1;

    for(i=0;i<n;i++)
    {
        cin>>str;

        for(j=0;j<str.length();j++)
        {
            if(str[j]>='0'&&str[j]<='9')
                rating2++;
            for(k=1;k<str.length()-1;k++)
            {
                if(str[j]==str[k])
                    sum++;
            }
        }
        if(sum==m)
        {
            rating++;
        }
        sum=0;

        if(i>=1)
        {
            if(str1==str)
                l++;
        }
        str1=str;
    }

    if(rating!=m||l>=1||rating2<n*m)
      cout<<"NO"<<endl;
    else
         cout<<"YES"<<endl;

    return 0;
}


'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:24/05/2020

'''
import sys
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def read():
    tc=0
    if tc:
        input=sys.stdin.readline
    else:
        sys.stdin=open('input1.txt', 'r')
        sys.stdout=open('output1.txt','w')

def solve():

    for _ in range(ii()):

        n,m=mi()
        tot=pow(2,m)-n
        x=(tot-1)//2
        a=[]
        for i in range(n):
            s=si()
            a.append(int(s,2))
        a.sort()
        cnt=bisect(a,x)
        x+=cnt
        c=cnt
        while(cnt):
            cnt=bisect(a,x)-c
            x+=cnt
            c+=cnt
        s=bin(x)[2:]
        print('0'*(m-len(s))+s)

if __name__ =="__main__":
    # read()
    solve()


'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:24/05/2020

'''
import sys
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def read():
    tc=0
    if tc:
        input=sys.stdin.readline
    else:
        sys.stdin=open('input1.txt', 'r')
        sys.stdout=open('output1.txt','w')

def solve():

    for _ in range(ii()):

        n,m=mi()
        a=[]
        x=pow(2,m)-n
        x=ceil(x/2)
        for i in range(n):
            a.append(si())
        a.sort()
        f=0
        for i in range(n):
            y=0
            for j in range(m):
                if(a[i][j]=='1'):
                    y+=pow(2,m-j-1)
            if(y==x+i):
                s=bin(y-1)[2:]
                s='0'*(m-len(s))+s
                print(s)
                f=1
                break
            if(y>(x+i)):
                f=1
                x+=i
                s=bin(x-1)[2:]
                s='0'*(m-len(s))+s
                print(s)
                break

        if(f==0):
            print('1'*m)

if __name__ =="__main__":
    read()
    solve()


'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:24/05/2020

'''
import sys
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def read():
    tc=0
    if tc:
        input=sys.stdin.readline
    else:
        sys.stdin=open('input1.txt', 'r')
        sys.stdout=open('output1.txt','w')

def solve():

    for _ in range(ii()):

        n,m=mi()
        a=[]
        x=pow(2,m)-n
        x=ceil(x/2)
        for i in range(n):
            a.append(si())
        a.sort()
        f=0
        for i in range(n):
            y=0
            for j in range(m):
                if(a[i][j]=='1'):
                    y+=pow(2,m-j-1)
            if(y==x+i):
                s=bin(y-1)[2:]
                s='0'*(m-len(s))+s
                print(s)
                f=1
                break
            if(y>(x+i)):
                f=1
                x+=i
                s=bin(x-1)[2:]
                s='0'*(m-len(s))+s
                print(s)
                break

        if(f==0):
            print('1'*m)

if __name__ =="__main__":
    #read()
    solve()


t = int(input())
for _ in range(t):
    n,m = map(int,input().split())
    k = 2**m-n
    l = [-1]
    for i in range(n):
        s = input()[::-1]
        c = 0
        for j in range(m):
            if s[j] == "1":
                c += pow(2,j)
        l.append(c)
    l.sort()
    l.append(2**m)
    count = (k+1)//2
    for i in range(1,n+2):
        dif = l[i]-l[i-1]-1
        if dif < count:
            count -= dif
        else:
            ans = l[i-1]+count
            break
    ans = bin(ans)[2:]
    print(ans.zfill(m))


import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##############################################3
t=int(input())
from collections import defaultdict
for i in range(t):
    n,m=map(int,input().split())
    l=[]
    d=defaultdict(int)
    for j in range(n):
        l.append(int(input(),2))
    x=pow(2,m-1)-1
    ln=0
    for j in l:
        if ln%2!=0:
            if j>=x:
                x-=1
                while d[x]==1:
                    x-=1
                d[j]=1
            else:
                d[j]=1
        else:
            if j<=x:
                x+=1
                while d[x]==1:
                    x+=1
                d[j]=1
            else:
                d[j]=1
        ln=ln^1
    ans=bin(x).lstrip('0b')
    ans='0'*(m-len(ans))+ans
    print(ans)


for _ in range(int(input())):
    n, m = map(int, input().split())
    a = [int(input(), 2) for _ in range(n)]
    x = (2 ** m - n - 1) // 2
    for v in sorted(a):
        if v <= x:
            x += 1
    print("{0:0={1}b}".format(x, m))


t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    a = sorted([int(input(), 2) for _ in range(n)])
    rem = (2**m) - n
    lo = (rem-1) // 2
    for x in a:
        if x <= lo:
            lo += 1
    print '0'*(m-len(bin(lo))+2) + bin(lo)[2:]


import bisect
TT = int(input())

for loop in range(TT):

    n,m = map(int,input().split())

    rem = []
    rd = {}

    for i in range(n):
        x = input()
        rem.append(int(x,2))
        rd[int(x,2)] =1

    rem.sort()

    l = -1
    r = 2**m-1

    k = 2**m-n
    d = (k-1)//2

    while r-l != 1:

        mid = (l+r)//2

        mininum = bisect.bisect_left(rem,mid)

        if mid-mininum >= d:
            r = mid
        else:
            l = mid

    while r in rd:
        r += 1
    print (format(r,'b').zfill(m))


import bisect
TT = int(input())

for loop in range(TT):

    n,m = map(int,input().split())

    rem = []

    for i in range(n):
        x = input()
        rem.append(int(x,2))

    l = -1
    r = 2**m-1

    k = 2**m-n
    d = (k-1)//2

    while r-l != 1:

        mid = (l+r)//2

        mininum = bisect.bisect_right(rem,mid)

        if mid-mininum >= d:
            r = mid
        else:
            l = mid

    print (format(r,'b').zfill(m))


import bisect
TT = int(input())

for loop in range(TT):

    n,m = map(int,input().split())

    rem = []
    rd = {}

    for i in range(n):
        x = input()
        rem.append(int(x,2))
        rd[int(x,2)] =1

    l = -1
    r = 2**m-1

    k = 2**m-n
    d = (k-1)//2

    while r-l != 1:

        mid = (l+r)//2

        mininum = bisect.bisect_left(rem,mid)

        if mid-mininum >= d:
            r = mid
        else:
            l = mid

    while r in rd:
        r += 1
    print (format(r,'b').zfill(m))


def binary_number(line):
    count = len(line)
    number = 0
    degree = 0
    for x in range(count):
        if line[x] == '1':
            number += pow(2, count - 1 - degree)
        degree += 1

    return number

def binary_line(number, long):
    line = ''
    for x in range(long):
        if number % 2 == 1:
            line = '1' + line
        else:
            line = '0' + line
        number = number // 2

    return line

tests = int(input())
for i in range(tests):
    numbers = input().split()

    n = int(numbers[0])
    m = int(numbers[1])

    deleted = []
    position = (pow(2, m) - n - 1) // 2

    for x in range(n):
        deleted.append(binary_number(input()))

    deleted.sort()

    for x in range(len(deleted)):
        if deleted[x] <= position:
            position += 1
        else:
            break

    print(binary_line(position, m))


# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
#threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353

# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
#sys.setrecursionlimit(300000)

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# -------------------game starts now----------------------------------------------------import math
class TreeNode:
    def __init__(self, k, v):
        self.key = k
        self.value = v
        self.left = None
        self.right = None
        self.parent = None
        self.height = 1
        self.num_left = 1
        self.num_total = 1

class AvlTree:

    def __init__(self):
        self._tree = None

    def add(self, k, v):
        if not self._tree:
            self._tree = TreeNode(k, v)
            return
        node = self._add(k, v)
        if node:
            self._rebalance(node)

    def _add(self, k, v):
        node = self._tree
        while node:
            if k < node.key:
                if node.left:
                    node = node.left
                else:
                    node.left = TreeNode(k, v)
                    node.left.parent = node
                    return node.left
            elif node.key < k:
                if node.right:
                    node = node.right
                else:
                    node.right = TreeNode(k, v)
                    node.right.parent = node
                    return node.right
            else:
                node.value = v
                return

    @staticmethod
    def get_height(x):
        return x.height if x else 0

    @staticmethod
    def get_num_total(x):
        return x.num_total if x else 0

    def _rebalance(self, node):

        n = node
        while n:
            lh = self.get_height(n.left)
            rh = self.get_height(n.right)
            n.height = max(lh, rh) + 1
            balance_factor = lh - rh
            n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
            n.num_left = 1 + self.get_num_total(n.left)

            if balance_factor > 1:
                if self.get_height(n.left.left) < self.get_height(n.left.right):
                    self._rotate_left(n.left)
                self._rotate_right(n)
            elif balance_factor < -1:
                if self.get_height(n.right.right) < self.get_height(n.right.left):
                    self._rotate_right(n.right)
                self._rotate_left(n)
            else:
                n = n.parent

    def _remove_one(self, node):
        """
        Side effect!!! Changes node. Node should have exactly one child
        """
        replacement = node.left or node.right
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = replacement
            else:
                node.parent.right = replacement
            replacement.parent = node.parent
            node.parent = None
        else:
            self._tree = replacement
            replacement.parent = None
        node.left = None
        node.right = None
        node.parent = None
        self._rebalance(replacement)

    def _remove_leaf(self, node):
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = None
            else:
                node.parent.right = None
            self._rebalance(node.parent)
        else:
            self._tree = None
        node.parent = None
        node.left = None
        node.right = None

    def remove(self, k):
        node = self._get_node(k)
        if not node:
            return
        if AvlTree._is_leaf(node):
            self._remove_leaf(node)
            return
        if node.left and node.right:
            nxt = AvlTree._get_next(node)
            node.key = nxt.key
            node.value = nxt.value
            if self._is_leaf(nxt):
                self._remove_leaf(nxt)
            else:
                self._remove_one(nxt)
            self._rebalance(node)
        else:
            self._remove_one(node)

    def get(self, k):
        node = self._get_node(k)
        return node.value if node else -1

    def _get_node(self, k):
        if not self._tree:
            return None
        node = self._tree
        while node:
            if k < node.key:
                node = node.left
            elif node.key < k:
                node = node.right
            else:
                return node
        return None

    def get_at(self, pos):
        x = pos + 1
        node = self._tree
        while node:
            if x < node.num_left:
                node = node.left
            elif node.num_left < x:
                x -= node.num_left
                node = node.right
            else:
                return (node.key, node.value)
        raise IndexError("Out of ranges")

    @staticmethod
    def _is_left(node):
        return node.parent.left and node.parent.left == node

    @staticmethod
    def _is_leaf(node):
        return node.left is None and node.right is None

    def _rotate_right(self, node):
        if not node.parent:
            self._tree = node.left
            node.left.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.left
            node.left.parent = node.parent
        else:
            node.parent.right = node.left
            node.left.parent = node.parent
        bk = node.left.right
        node.left.right = node
        node.parent = node.left
        node.left = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    def _rotate_left(self, node):
        if not node.parent:
            self._tree = node.right
            node.right.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.right
            node.right.parent = node.parent
        else:
            node.parent.right = node.right
            node.right.parent = node.parent
        bk = node.right.left
        node.right.left = node
        node.parent = node.right
        node.right = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    @staticmethod
    def _get_next(node):
        if not node.right:
            return node.parent
        n = node.right
        while n.left:
            n = n.left
        return n

# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
    def __init__(self, data, default=300006, func=lambda a, b: min(a , b)):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
    def __init__(self, data, default=0, func=lambda a, b:a + b):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorials = [1, 1]
        self.invModulos = [0, 1]
        self.invFactorial_ = [1, 1]

    def calc(self, n):
        if n <= -1:
            print("Invalid argument to calculate n!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.factorials):
            return self.factorials[n]
        nextArr = [0] * (n + 1 - len(self.factorials))
        initialI = len(self.factorials)
        prev = self.factorials[-1]
        m = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = prev * i % m
        self.factorials += nextArr
        return self.factorials[n]

    def inv(self, n):
        if n <= -1:
            print("Invalid argument to calculate n^(-1)")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        p = self.MOD
        pi = n % p
        if pi < len(self.invModulos):
            return self.invModulos[pi]
        nextArr = [0] * (n + 1 - len(self.invModulos))
        initialI = len(self.invModulos)
        for i in range(initialI, min(p, n + 1)):
            next = -self.invModulos[p % i] * (p // i) % p
            self.invModulos.append(next)
        return self.invModulos[pi]

    def invFactorial(self, n):
        if n <= -1:
            print("Invalid argument to calculate (n^(-1))!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.invFactorial_):
            return self.invFactorial_[n]
        self.inv(n)  # To make sure already calculated n^-1
        nextArr = [0] * (n + 1 - len(self.invFactorial_))
        initialI = len(self.invFactorial_)
        prev = self.invFactorial_[-1]
        p = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
        self.invFactorial_ += nextArr
        return self.invFactorial_[n]

class Combination:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorial = Factorial(MOD)

    def ncr(self, n, k):
        if k < 0 or n < k:
            return 0
        k = min(k, n - k)
        f = self.factorial
        return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m

# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
    zipped_pairs = zip(list2, list1)

    z = [x for _, x in sorted(zipped_pairs)]

    return z

# --------------------------------------------------product----------------------------------------
def product(l):
    por = 1
    for i in range(len(l)):
        por *= l[i]
    return por

# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
    left = 0
    right = n - 1

    count = 0

    while (left <= right):
        mid = int((right + left) / 2)

        # Check if middle element is
        # less than or equal to key
        if (arr[mid] <=key):
            count = mid + 1
            left = mid + 1

        # If key is smaller, ignore right half
        else:
            right = mid - 1

    return count

# --------------------------------------------------binary----------------------------------------
def countdig(n):
    c = 0
    while (n > 0):
        n //= 10
        c += 1
    return c
def binary(x, length):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

def countGreater(arr, n, k):
    l = 0
    r = n - 1

    # Stores the index of the left most element
    # from the array which is greater than k
    leftGreater = n

    # Finds number of elements greater than k
    while (l <= r):
        m = int(l + (r - l) / 2)
        if (arr[m] > k):
            leftGreater = m
            r = m - 1

        # If mid element is less than
        # or equal to k update l
        else:
            l = m + 1

    # Return the count of elements
    # greater than k
    return (n - leftGreater)

# --------------------------------------------------binary------------------------------------
class TrieNode:
    def __init__(self):
        self.children = [None] * 26
        self.isEndOfWord = False
class Trie:
    def __init__(self):
        self.root = self.getNode()
    def getNode(self):
        return TrieNode()
    def _charToIndex(self, ch):
        return ord(ch) - ord('a')
    def insert(self, key):
        pCrawl = self.root
        length = len(key)
        for level in range(length):
            index = self._charToIndex(key[level])
            if not pCrawl.children[index]:
                pCrawl.children[index] = self.getNode()
            pCrawl = pCrawl.children[index]
        pCrawl.isEndOfWord = True
    def search(self, key):
        pCrawl = self.root
        length = len(key)
        for level in range(length):
            index = self._charToIndex(key[level])
            if not pCrawl.children[index]:
                return False
            pCrawl = pCrawl.children[index]
        return pCrawl != None and pCrawl.isEndOfWord
#-----------------------------------------trie---------------------------------
class Node:
    def __init__(self, data):
        self.data = data
        self.count=0
        self.left = None  # left node for 0
        self.right = None  # right node for 1
class BinaryTrie:
    def __init__(self):
        self.root = Node(0)
    def insert(self, pre_xor):
        self.temp = self.root
        for i in range(31, -1, -1):
            val = pre_xor & (1 << i)
            if val:
                if not self.temp.right:
                    self.temp.right = Node(0)
                self.temp = self.temp.right
                self.temp.count+=1
            if not val:
                if not self.temp.left:
                    self.temp.left = Node(0)
                self.temp = self.temp.left
                self.temp.count += 1
        self.temp.data = pre_xor
    def query(self, xor):
        self.temp = self.root
        for i in range(31, -1, -1):
            val = xor & (1 << i)
            if not val:
                if self.temp.left and self.temp.left.count>0:
                    self.temp = self.temp.left
                elif self.temp.right:
                    self.temp = self.temp.right
            else:
                if self.temp.right and self.temp.right.count>0:
                    self.temp = self.temp.right
                elif self.temp.left:
                    self.temp = self.temp.left
            self.temp.count-=1
        return xor ^ self.temp.data
#-------------------------bin trie-------------------------------------------
for ik in range(int(input())):
    m,n=map(int,input().split())
    ans=2**(n-1)-1
    n=2**n
    pre=ans
    nex=ans+1
    prev=[i-1 for i in range(n+5)]
    next=[i+1 for i in range(n+5)]
    s=set()
    for i in range(m):
        w=int(input(),2)
        s.add(w)
        if w<ans:
            next[w - 1] = w + 1
            prev[w + 1] = w - 1
            if pre==nex:
                pre-=1
            else:
                while(next[ans] in s):
                    ans=next[ans]
                ans=next[ans]
                nex-=1
        elif w>ans:
            next[w - 1] = w + 1
            prev[w + 1] = w - 1
            if pre<nex:
                nex-=1
            else:
                while (prev[ans] in s):
                    ans = prev[ans]
                ans = prev[ans]
                pre-=1
        else:
            next[w - 1] = w + 1
            prev[w + 1] = w - 1
            if pre==nex:
                while (prev[ans] in s):
                    ans = prev[ans]
                ans = prev[ans]
                pre-=1
            else:
                while (next[ans] in s):
                    ans = next[ans]
                ans = next[ans]
                nex -= 1
    print(bin(ans)[2:])