#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np H, W = map(int, readline().split()) A = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W].astype(int) def solve(A): H, W = A.shape if H == 1 and W == 1: return A[0, 0] == 1 is_monotone_col = np.isin(np.sum(A, axis=0), [0, H]) is_monotone_row = np.isin(np.sum(A, axis=1), [0, W]) return not (np.any(is_monotone_col) and np.any(is_monotone_row)) print('YES' if solve(A) else 'NO')