n,m=map(int,input().split()) a=[list(map(int,input().split())) for i in'.'*m] b=[[0]*n for i in'.'*m] b[0]=[x for x in a[0]] for i in range(1,m): for j in range(n): b[i][j]=b[i-1][j]+a[i][j] v='NO' for l in b: for i in range(n): for j in range(len(l)-i): if sum(l[i:1+i+j])==777: v='YES' break print(v)