#include <iostream>
#include <stack>
#include <utility>
#define down 10
#define left -1
#define right 1
#define up -10
using namespace std;

void print(int n, int m, int** matrix)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (matrix[i][j] == 0 || matrix[i][j] == 1)
				cout << matrix[i][j] << " ";
			else
				cout << (char)matrix[i][j] << " ";
		}
		cout << endl;
	}
}

bool search(int n, int m, int** matrix, stack<pair<int,int>>& route, int dir)
{
	pair<int, int> npos = make_pair(dir / 10 + route.top().first, dir % 10 + route.top().second);
	if (npos.first < 0 || npos.first >= n || npos.second < 0 || npos.second >= m || matrix[npos.first][npos.second] != 0)
		return false;
	else
	{
		route.push(npos);
		matrix[npos.first][npos.second] = 1;
		if (npos.first == n - 1)
			return true;
		else
		{
			int* priorityDirs;
			switch (dir)
			{
				case down:
					priorityDirs = new int[3]{left, down, right};
					break;
				case left:
					priorityDirs = new int[3]{left, down, up};
					break;
				case right:
					priorityDirs = new int[3]{down, right, up};
					break;
				case up:
					priorityDirs = new int[3]{left, right, up};
					break;
			}
			bool found = true;
			for (int i = 0; i < 3; i++)
			{
				found = search(n, m, matrix, route, priorityDirs[i]);
				if (found)
					return true;
			}
			matrix[npos.first][npos.second] = 0;
			route.pop();
			return false;
		}
	}
}

stack<pair<int,int>> findRoute(int n, int m, int** matrix, int begin)
{
	stack<pair<int,int>> route;
	route.push(make_pair(0, begin));
	if (n != 1 && !search(n, m, matrix, route, down))
		throw -1;
	return route;
}

int main() 
{
	ios::sync_with_stdio(false);
	int n, m;
	scanf("%d%d", &n, &m);
	int** matrix = new int*[n];
	for (int i = 0; i < n; i++)
		matrix[i] = new int[m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			scanf("%d", &matrix[i][j]);
	bool possible = true;
	int symbol = -1;
	for (int i = 0; i < m; i++)
	{
		if (matrix[0][i] == 0)
		{
			symbol++;
			try
			{
				stack<pair<int,int>> route = findRoute(n, m, matrix, i);
				while (!route.empty())
				{
					pair<int, int> pos = route.top();
					matrix[pos.first][pos.second] = 'a' + symbol;
					route.pop();
				}
			}
			catch (...)
			{
				possible = false;
				break;
			}
		}
	}
	cout << (possible ? "YES" : "NO") << endl;
	/*
	if (possible)
		print(n, m, matrix);
	*/
	return 0;
}