n, k = map(int, input().split())
a = []
for i in range(n):
a.append(input())
ans = 0
for i1 in range(0, n):
for j1 in range(0, n):
for l in range(0, n - max(i1, j1) + 1):
i2 = i1 + l
j2 = j1 + l
cnt = 0
for i in range(i1, i2):
for j in range(j1, j2):
if a[i][j] == '1':
cnt += 1
if cnt <= k:
ans = max(ans, l)
print(ans)