while (w, h = gets.chomp.split(" ").map{|str| str.to_i}) != [0, 0]
	queue = []
	table = []
	for y in 0..(h - 1)
		table << gets.chomp.split("").map.with_index do |char, x|
			if char == "."
				0
			elsif char == "#"
				-1
			elsif char == "@"
				queue << [y, x]
				0
			end
		end
	end
	while !queue.empty?
		y, x = queue.shift
		if table[y][x] == 0
			table[y][x] = 1
			queue << [y, x - 1] if x != 0 
			queue << [y - 1, x] if y != 0
			queue << [y, x + 1] if x != w - 1
			queue << [y + 1, x] if y != h - 1
		end
	end
	puts table.flatten.count(1)
end