def dfs a,x,y
	a[x][y]="o" if a[x][y] != "o"
	dfs a,x-1,y if x-1 >= 0 && a[x-1][y] == "."
	dfs a,x+1,y if x+1 < a.length && a[x+1][y] == "."
	dfs a,x,y-1 if y-1 >= 0 && a[x][y-1] == "."
	dfs a,x,y+1 if y+1 < a[0].length && a[x][y+1] == "."
end

while true
	args = gets.split(" ").map{|e|e.to_i}
	break if args[0] == 0 && args[1] == 0
	a=[]
	start=[-1,-1]
	args[1].times{|i|
		a.push gets.chomp
		if a[i].index("@") != nil
			start=i,a[i].index("@")
		end
	}
	dfs a,start[0],start[1]
	count = 0
	a.each{|e|count+=e.count("o")}
	p count
end