# 氷の破壊

def move(block, i, j, count, n, m)
  block[i][j] = 0
  count[0] += 1
  #print block
  #puts "１つ目" + "\n"
  [[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
      count = move(block, i+y, j+x, count, n, m)
      #print block
      #puts "2つ目" + "\n"
      #puts count[0]
      count[1] = count[0] if count[0] > count[1]
      #print count
      #print "\n"
      count[0] = 1
    end

  end

  block[i][j] = 1
  #print block
  #puts "3つ目" + "\n"
  return count
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|

      # 1つ目がcount、2つ目がmax
      count = [0,0]

      if block[i][j] == 1
        count = move(block, i, j, count, n, m)
      end

      max = count[1] if count[1] > max
    end
  end
  puts max
end

