def b(M,x,y,n=1):

 M[x][y]=0;t=[]

 if M[x-1][y]:t+=[b(M,x-1,y,n+1)]

 if M[x][y-1]:t+=[b(M,x,y-1,n+1)]

 if M[x+1][y]:t+=[b(M,x+1,y,n+1)]

 if M[x][y+1]:t+=[b(M,x,y+1,n+1)]

 M[x][y]=1

 return max([n]+t)

for e in iter(input,'0'):

 n,m=int(e),int(eval(input()))

 P=[[0]*(n+2)for _ in[0]*(m+2)]

 for i in range(m):P[i+1][1:-1]=list(map(int,input().split()))

 print((max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if P[i][j])))

def b(M,x,y,n=1):

 M[x][y]=0;a=n

 if M[x-1][y]:a=max(a,b(M,x-1,y,n+1))

 if M[x][y-1]:a=max(a,b(M,x,y-1,n+1))

 if M[x+1][y]:a=max(a,b(M,x+1,y,n+1))

 if M[x][y+1]:a=max(a,b(M,x,y+1,n+1))

 M[x][y]=1

 return a

for e in iter(input,'0'):

 n,m=int(e),int(eval(input()))

 P=[[0]*(n+2)for _ in[0]*(m+2)]

 for i in range(m):P[i+1][1:-1]=list(map(int,input().split()))

 print((max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if P[i][j])))

def b(M, x, y, n=1):
    M[x][y] = 0
    t = []
    if M[x - 1][y]:
        t += [b(M, x - 1, y, n + 1)]
    if M[x][y - 1]:
        t += [b(M, x, y - 1, n + 1)]
    if M[x + 1][y]:
        t += [b(M, x + 1, y, n + 1)]
    if M[x][y + 1]:
        t += [b(M, x, y + 1, n + 1)]
    M[x][y] = 1
    return max([n] + t)


for e in iter(input, "0"):
    n, m = int(e), int(eval(input()))
    P = [[0] * (n + 2) for _ in [0] * (m + 2)]
    for i in range(m):
        P[i + 1][1:-1] = list(map(int, input().split()))
    print(
        (max(b(P, i, j) for i in range(1, m + 1) for j in range(1, n + 1) if P[i][j]))
    )

def b(M, x, y, n=1):
    M[x][y] = 0
    a = n
    if M[x - 1][y]:
        a = max(a, b(M, x - 1, y, n + 1))
    if M[x][y - 1]:
        a = max(a, b(M, x, y - 1, n + 1))
    if M[x + 1][y]:
        a = max(a, b(M, x + 1, y, n + 1))
    if M[x][y + 1]:
        a = max(a, b(M, x, y + 1, n + 1))
    M[x][y] = 1
    return a


for e in iter(input, "0"):
    n, m = int(e), int(eval(input()))
    P = [[0] * (n + 2) for _ in [0] * (m + 2)]
    for i in range(m):
        P[i + 1][1:-1] = list(map(int, input().split()))
    print(
        (max(b(P, i, j) for i in range(1, m + 1) for j in range(1, n + 1) if P[i][j]))
    )

-    t = [] +    a = n -        t += [b(M, x - 1, y, n + 1)] +        a = max(a, b(M, x - 1, y, n + 1)) -        t += [b(M, x, y - 1, n + 1)] +        a = max(a, b(M, x, y - 1, n + 1)) -        t += [b(M, x + 1, y, n + 1)] +        a = max(a, b(M, x + 1, y, n + 1)) -        t += [b(M, x, y + 1, n + 1)] +        a = max(a, b(M, x, y + 1, n + 1)) -    return max([n] + t) +    return a