#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <sstream>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

int w,h;
int in[100][100];
int ans;

int qidx;
int st[100][100];
PI qu[100];
PI pu[100];
int choco;

int pst[100][100];
int qst[100][100];

void dfs(int ne, int d,int us=0){
  if(ans) return;
  // cout << ne << " " << d << endl;
  // rep(i,h){
  //   rep(j,w) cout << st[i][j] << " ";
  //   cout << endl;
  // }
  if(us*2 == choco){
    ans = 1;
    return;
  }
  
  int kidx = qidx;
  
  for(int i = ne; i < kidx; ++i){
    int cx = qu[i].F;
    int cy = qu[i].S;
    int px = pu[i].F;
    int py = pu[i].S;
    if(st[cx][cy]>1 || st[px][py]>1)
      continue;
    
    
    rep(kk,2){
      bool ok = ne == 0;
      bool ok2 = ne == 0;
      st[cx][cy] = 2;
      st[px][py] = 3;
      vector<PI> pre,qre;
      int bidx = qidx;
      //cout << cx << " " << cy << " " << px << " " << py << endl;
      
      rep(j,4){
        int nx = cx + dx[j];
        int ny = cy + dy[j];
        int pnx = px + dx[(j+d)%4];
        int pny = py + dy[(j+d)%4];
        if(d>3){
          pnx = px - dx[(j+d)%4];
          pny = py + dy[(j+d)%4];
          //cout << dx[(j+d)%4] << " " << - dy[(j+d)%4] << endl;
        }
        
        //cout << nx << " " << ny << " " << pnx << " " << pny << endl;
        if(nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
        //cout << nx << " " << ny << " " << pnx << " " << pny << endl;
        if(pnx < 0 || pny < 0 || pnx >= h || pny >= w) continue;
        //cout << nx << " " << ny << " " << pnx << " " << pny << endl;
        ok |= st[nx][ny] == 2;
        ok2 |= st[pnx][pny] == 3;
        if(st[nx][ny] || st[pnx][pny]) continue;
        if(pst[nx][ny] || !in[nx][ny]) continue;
        if(qst[pnx][pny] || !in[pnx][pny]) continue;
        if(nx == pnx && ny == pny) continue;
        pst[nx][ny] = 1;
        qst[pnx][pny] = 1;
        pre.pb(mp(nx,ny));
        qre.pb(mp(pnx,pny));
        pu[qidx] = mp(nx,ny);
        qu[qidx++] = mp(pnx, pny);
      }
      //cout << ok << endl;
      if(ok && ok2)
        dfs(i+1,d,us+1);
      for(auto e : pre) pst[e.first][e.second] = 0;
      for(auto e : qre) qst[e.first][e.second] = 0;
      st[cx][cy] = 0;
      st[px][py] = 0;
      qidx = kidx;
      swap(cx,px);
      swap(cy,py);
    }
  }
  
}


void solve(){
  ans = 0;
  rep(i,h)rep(j,w) cin >> in[i][j];
  vector<PI> app;
  rep(i,h)rep(j,w) if(in[i][j]) app.pb(mp(i,j));

  if(app.size()%2){
    cout << "NO" << endl;
    return;
  }
  choco = SZ(app);
  //app = vector<PI>({app[0], mp(2,2)});
  
  rep(i,SZ(app)-1){
    rep(j,8){
      memset(st, 0, sizeof(st));
      memset(pst, 0, sizeof(pst));
      memset(qst, 0, sizeof(qst));
      qidx = 0;
      qu[qidx++] = app[0];
      pu[0] = app[i+1];
      st[app[0].F][app[0].S] = 1;
      st[app[i+1].F][app[i+1].S] = 1;
      pst[app[0].F][app[0].S] = 1;
      qst[app[i+1].F][app[i+1].S] = 1;
      dfs(0, j);
    }
  }
  
  cout << (ans ? "YES":"NO") << endl;
}

int main(int argc, char *argv[])
{
  while(cin >> w >> h && w) solve();
}

Measured memory_bytes: 1332