def s():

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

  if M[x][y]==0:return n

  M[x][y]=0

  a=max(b(M,x-1,y,n+1),b(M,x,y-1,n+1),b(M,x+1,y,n+1),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'__main__'==__name__:s()

def s():

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

  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,1)for i in range(1,m+1)for j in range(1,n+1)if P[i][j])))

if'__main__'==__name__:s()

def s():
    def b(M, x, y, n=0):
        if M[x][y] == 0:
            return n
        M[x][y] = 0
        a = max(
            b(M, x - 1, y, n + 1),
            b(M, x, y - 1, n + 1),
            b(M, x + 1, y, n + 1),
            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 "__main__" == __name__:
    s()

def s():
    def b(M, x, y, n):
        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, 1)
                    for i in range(1, m + 1)
                    for j in range(1, n + 1)
                    if P[i][j]
                )
            )
        )


if "__main__" == __name__:
    s()

-    def b(M, x, y, n=0): -        if M[x][y] == 0: -            return n +    def b(M, x, y, n): -        a = max( -            b(M, x - 1, y, n + 1), -            b(M, x, y - 1, n + 1), -            b(M, x + 1, y, n + 1), -            b(M, x, y + 1, n + 1), -        ) +        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)) -        print((max(b(P, i, j) for i in range(1, m + 1) for j in range(1, n + 1)))) +        print( +            ( +                max( +                    b(P, i, j, 1) +                    for i in range(1, m + 1) +                    for j in range(1, n + 1) +                    if P[i][j] +                ) +            ) +        )