# ?????????????????¢?´¢????????¨?????£??????DFS??¨????????´??????
# ?????????????£?????????????????§£??¬????????????

@m = 0
@n = 0
@cells = []

def dfs cells,y,x,cur
  cells[y][x] = false
  sur = [
    [y + 1, x],
    [y - 1, x],
    [y, x + 1],
    [y, x - 1]
  ]

  results = []
  did = false
  sur.each do |(ny, nx)|
    next if ny >= @n || nx >= @m || nx < 0 || ny < 0
    next unless cells[ny][nx]
    did = true
    results << dfs(cells,ny, nx, cur + 1)
  end
  cells[y][x] = true
  unless did
    return cur + 1
  else
    return results.max || 0
  end
end

loop do
  @m = gets.to_i
  break if @m == 0
  @n = gets.to_i
  @cells = []
  @n.times { @cells << gets.split.map { |v| v == "1" } }

  flag = []
  max = 0
  @cells.each_with_index do |line, y|
    flag[y] = []
    line.each_with_index do |val, x|
      max = [dfs(@cells,y,x,0), max].max if val
    end
  end

  puts max

end