#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 10

enum Type{
	NOT,
	UNDEFINED,
	A,
	B,
};

struct Info{
	Info(){
		row = 0;
		col = 0;
	}
	Info(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	void set(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

int W,H;
int roll_type,base;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
int num_choco;
int index_table[NUM][NUM];
Type table[NUM][NUM],work[NUM][NUM],pre[NUM][NUM];
bool FLG;
Info info[36];

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1){
		return true;
	}else{
		return false;
	}
}

//連結か調べる
bool connectCheck(Type type){

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			work[row][col] = table[row][col];
		}
	}

	int count = 0;
	int adj_row,adj_col;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(work[row][col] != type)continue;

			count++;
			work[row][col] = UNDEFINED;
			queue<Info> Q;
			Q.push(Info(row,col));

			while(!Q.empty()){

				for(int i = 0; i < 4; i++){

					adj_row = Q.front().row+diff_row[i];
					adj_col = Q.front().col+diff_col[i];

					if(!rangeCheck(adj_row,adj_col))continue;

					if(work[adj_row][adj_col] == type){
						count++;
						work[adj_row][adj_col] = UNDEFINED;
						Q.push(Info(adj_row,adj_col));
					}
				}
				Q.pop();
			}

			return count == num_choco/2;
		}
	}

	return false;
}

Info get_Pos(int base_row,int base_col){

	Info ret;

	//左上からの相対位置
	base_row -= info[0].row;
	base_col -= info[0].col;

	if(roll_type >= 4){
		base_row *= -1;
	}

	if(roll_type%4 == 0){

		ret.row = base_row;
		ret.col = base_col;

	}else if(roll_type%4 == 1){

		//90度回転
		ret.row = base_col;
		ret.col = -base_row;

	}else if(roll_type%4 == 2){

		ret.row = -base_row;
		ret.col = -base_col;

	}else{

		ret.row = -base_col;
		ret.col = base_row;
	}

	ret.row += info[base].row;
	ret.col += info[base].col;

	return ret;
}

Info get_Rev_Pos(int base_row,int base_col){

	Info ret;

	base_row -= info[base].row;
	base_col -= info[base].col;

	if(roll_type%4 == 0){

		ret.row = base_row;
		ret.col = base_col;

	}else if(roll_type%4 == 1){

		//90度回転
		ret.row = -base_col;
		ret.col = base_row;

	}else if(roll_type%4 == 2){

		ret.row = -base_row;
		ret.col = -base_col;

	}else{

		ret.row = base_col;
		ret.col = -base_row;
	}

	if(roll_type >= 4){
		ret.row *= -1;
	}

	ret.row += info[0].row;
	ret.col += info[0].col;

	return ret;
}

void recursive(int index,int decided_num){

	if(FLG)return;

	if(decided_num == num_choco/2){

		if(connectCheck(A) == false || connectCheck(B) == false)return;

		FLG = true;

		return;
	}

	if(decided_num+(num_choco-index) < num_choco/2)return;

	if(table[info[index].row][info[index].col] != UNDEFINED){
		recursive(index+1,decided_num);
		return;
	}

	Info tmp_info;
	int tmp_index;

	tmp_info = get_Pos(info[index].row,info[index].col);

	if(rangeCheck(tmp_info.row,tmp_info.col)){
		tmp_index = index_table[tmp_info.row][tmp_info.col];
		if(tmp_index != -1 && tmp_index != index && table[info[tmp_index].row][info[tmp_index].col] == UNDEFINED){
			table[info[index].row][info[index].col] = A;
			table[info[tmp_index].row][info[tmp_index].col] = B;
			recursive(index+1,decided_num+1);
			table[info[index].row][info[index].col] = UNDEFINED;
			table[info[tmp_index].row][info[tmp_index].col] = UNDEFINED;
		}
	}


	tmp_info = get_Rev_Pos(info[index].row,info[index].col);

	if(rangeCheck(tmp_info.row,tmp_info.col)){
		tmp_index = index_table[tmp_info.row][tmp_info.col];
		if(tmp_index != -1 && tmp_index != index && table[info[tmp_index].row][info[tmp_index].col] == UNDEFINED){
			table[info[index].row][info[index].col] = B;
			table[info[tmp_index].row][info[tmp_index].col] = A;
			recursive(index+1,decided_num+1);
			table[info[index].row][info[index].col] = UNDEFINED;
			table[info[tmp_index].row][info[tmp_index].col] = UNDEFINED;
		}
	}
}


void func(){

	num_choco = 0;

	int tmp;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			table[row][col] = NOT;
			index_table[row][col] = -1;
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			scanf("%d",&tmp);
			if(tmp == 1){
				table[row][col] = UNDEFINED;
				info[num_choco].set(row,col);
				index_table[row][col] = num_choco;
				num_choco++;
			}
		}
	}

	if(num_choco%2 == 1){
		printf("NO\n");
		return;
	}

	FLG = false;

	for(base = 1; base < num_choco; base++){
		for(roll_type = 0; roll_type < 8; roll_type++){
			recursive(0,0);
			if(FLG){
				printf("YES\n");
				return;
			}
		}
	}
	printf("NO\n");
}

int main(){

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3160