while (ln = gets.chomp) != "0 0"
  w,h = ln.split.map(&:to_i)
  s = h.times.map{gets.split.map(&:to_i)}
  
  cnts = Array.new(h).map{Array.new(w,0)}
  vis = Array.new(h).map{Array.new(w,0)}
  sel = Array.new(h).map{Array.new(w,0)}
  cnt = 1
  for i in 0..(h-1)
    for j in 0..(w-1)
      if s[i][j] == 1 && vis[i][j] == 0
        ln = [i]
        ro = [j]
        id = 0
        idmax = 0
        
        while id <= idmax
          x = ro[id]
          y = ln[id]
          cnts[y][x] = cnt
          vis[y][x] = 1
          xdir = [x,x-1,x+1]
          ydir = [y,y-1,y+1]
          xdir.each do |xd|
            ydir.each do |yd|
              if xd != x || yd != y
                if 0<=xd && xd<w && 0<=yd && yd<h && s[yd][xd]==1 && vis[yd][xd]==0 && sel[yd][xd]==0
                  sel[yd][xd] = 1
                  ln.push(yd)
                  ro.push(xd)
                  idmax += 1
                end
              end
            end
          end
          id += 1
        end
        
        cnt += 1
      end
    end
  end

  ans = 0
  for i in 0..(h-1)
    for j in 0..(w-1)
      ans = [ans,cnts[i][j]].max
    end
  end
  puts ans
end
