""" https://yukicoder.me/problems/no/1400 行列べき乗っぽく考えて しまいがちだが… これは01BFSで解ける まず、頂点を偶奇で分ける Dの偶奇に合わせて、最短距離が基底範囲内化出せばおk """ import sys from sys import stdin from collections import deque V,D = map(int,stdin.readline().split()) E = [ stdin.readline()[:-1] for i in range(V) ] for s in range(V): q = deque([s]) d = [float("inf")] * (2*V) d[s] = 0 while q: nowori = q.popleft() v = nowori side = 0 if v >= V: v -= V side = 1 for nex in range(V): if E[v][nex] == "1": nexori = nex + V * (side^1) if d[nexori] > d[nowori] + 1: d[nexori] = d[nowori] + 1 q.append(nexori) #print (s,d) if D % 2 == 0: for i in range(V): if d[i] > D: print ("No") sys.exit() else: for i in range(V,2*V): if d[i] > D: print ("No") sys.exit() print ("Yes")