def move(block, i, j, num, n, m)
  block[i][j] = 0
  results = []
  did = false
  [[0,-1],[1,0],[0,1],[-1,0]].each do |x,y|
    next if i+y < 0 || j+x < 0 || i+y >= n || j+x >= m
    if block[i+y][j+x] == 1
      did = true
      results << move(block, i+y, j+x, num+1, n, m)
    end
  end

  block[i][j] = 1
  if did 
    return results.max || 0
  else 
    return num
  end
end

loop do
  m = gets.chomp.to_i
  n = gets.chomp.to_i
  break if m == 0
  block = []
  n.times do
    block << gets.chomp.split(" ").map(&:to_i)
  end
  
  max = 0
  (0...n).each do |i|
    (0...m).each do |j|
      if block[i][j] == 1
        count = [move(block, i, j, 1, n, m), max]
        max = count.max
      end
    end
  end
  puts max
end

