while true
    w, h = gets.chomp.split.map(&:to_i)
    break if [w, h] == [0, 0]

    map = []
    x, y = nil, nil
    h.times{|j|
        line = gets.chomp
        map << line
        if z = line.index("@")
            x, y = z, j
        end
    }
#    map.each{|m| puts m}
#    puts "x#{x} y#{y}"
    sum = 0
    list = [[x, y]]
    until list.empty?
        x2, y2 = list.pop
        if map[y2][x2] != "#"
            map[y2][x2] = "#"
            sum += 1
            list << [x2+1, y2] if x2 < w-1 && map[y2][x2+1] == "."
            list << [x2-1, y2] if x2 > 0 && map[y2][x2-1] == "."
            list << [x2, y2+1] if y2 < h-1 && map[y2+1][x2] == "."
            list << [x2, y2-1] if y2 > 0 && map[y2-1][x2] == "."
        end
    end
    puts sum
#    puts
end
