import sys

from collections import deque



def solve():

    while 1:

        w, h = list(map(int, sys.stdin.readline().split()))



        if w == h == 0:

            return



        room = [[False]*w for i in range(h)]



        si = sj = -1



        for i in range(h):

            line = eval(input())



            for j, ch in enumerate(line):

                if ch == '@':

                    room[i][j] = True

                    si = i

                    sj = j

                elif ch == '.':

                    room[i][j] = True



        ans = bfs(w, h, room, si, sj)



        print(ans)



dx = (1, 0, -1, 0,)

dy = (0, 1, 0, -1,)



def bfs(w, h, room, si, sj):

    visited = [[False]*w for i in range(h)]

    visited[si][sj] = True

    q = deque([(si, sj)])

    cnt = 1



    while q:

        ci, cj = q.popleft()



        for k in range(len(dx)):

            ni = ci + dy[k]

            nj = cj + dx[k]



            if 0 <= ni < h and 0 <= nj < w and room[ni][nj] and not visited[ni][nj]:

                visited[ni][nj] = True

                q.append((ni, nj))

                cnt += 1



    return cnt



if __name__ == '__main__':

    solve()
import sys



cnt = 0



def solve():

    while 1:

        w, h = list(map(int, sys.stdin.readline().split()))



        if w == h == 0:

            return



        room = [list(sys.stdin.readline().rstrip()) for i in range(h)]



        for i in range(h):

            if '@' in room[i]:

                si = i

                sj = room[i].index('@')

                break



        global cnt

        cnt = 0

        dfs(w, h, room, si, sj)

        print(cnt)



def dfs(w, h, room, i, j):

    if i < 0 or i >= h or j < 0 or j >= w or (room[i][j] == '#'):

        return



    global cnt

    cnt += 1

    room[i][j] = '#'



    dfs(w, h, room, i + 1, j)

    dfs(w, h, room, i - 1, j)

    dfs(w, h, room, i, j + 1)

    dfs(w, h, room, i, j - 1)



if __name__ == '__main__':

    solve()
import sys
from collections import deque


def solve():
    while 1:
        w, h = list(map(int, sys.stdin.readline().split()))
        if w == h == 0:
            return
        room = [[False] * w for i in range(h)]
        si = sj = -1
        for i in range(h):
            line = eval(input())
            for j, ch in enumerate(line):
                if ch == "@":
                    room[i][j] = True
                    si = i
                    sj = j
                elif ch == ".":
                    room[i][j] = True
        ans = bfs(w, h, room, si, sj)
        print(ans)


dx = (
    1,
    0,
    -1,
    0,
)
dy = (
    0,
    1,
    0,
    -1,
)


def bfs(w, h, room, si, sj):
    visited = [[False] * w for i in range(h)]
    visited[si][sj] = True
    q = deque([(si, sj)])
    cnt = 1
    while q:
        ci, cj = q.popleft()
        for k in range(len(dx)):
            ni = ci + dy[k]
            nj = cj + dx[k]
            if 0 <= ni < h and 0 <= nj < w and room[ni][nj] and not visited[ni][nj]:
                visited[ni][nj] = True
                q.append((ni, nj))
                cnt += 1
    return cnt


if __name__ == "__main__":
    solve()

import sys

cnt = 0


def solve():
    while 1:
        w, h = list(map(int, sys.stdin.readline().split()))
        if w == h == 0:
            return
        room = [list(sys.stdin.readline().rstrip()) for i in range(h)]
        for i in range(h):
            if "@" in room[i]:
                si = i
                sj = room[i].index("@")
                break
        global cnt
        cnt = 0
        dfs(w, h, room, si, sj)
        print(cnt)


def dfs(w, h, room, i, j):
    if i < 0 or i >= h or j < 0 or j >= w or (room[i][j] == "#"):
        return
    global cnt
    cnt += 1
    room[i][j] = "#"
    dfs(w, h, room, i + 1, j)
    dfs(w, h, room, i - 1, j)
    dfs(w, h, room, i, j + 1)
    dfs(w, h, room, i, j - 1)


if __name__ == "__main__":
    solve()

-from collections import deque + +cnt = 0 -        room = [[False] * w for i in range(h)] -        si = sj = -1 +        room = [list(sys.stdin.readline().rstrip()) for i in range(h)] -            line = eval(input()) -            for j, ch in enumerate(line): -                if ch == "@": -                    room[i][j] = True -                    si = i -                    sj = j -                elif ch == ".": -                    room[i][j] = True -        ans = bfs(w, h, room, si, sj) -        print(ans) +            if "@" in room[i]: +                si = i +                sj = room[i].index("@") +                break +        global cnt +        cnt = 0 +        dfs(w, h, room, si, sj) +        print(cnt) -dx = ( -    1, -    0, -    -1, -    0, -) -dy = ( -    0, -    1, -    0, -    -1, -) - - -def bfs(w, h, room, si, sj): -    visited = [[False] * w for i in range(h)] -    visited[si][sj] = True -    q = deque([(si, sj)]) -    cnt = 1 -    while q: -        ci, cj = q.popleft() -        for k in range(len(dx)): -            ni = ci + dy[k] -            nj = cj + dx[k] -            if 0 <= ni < h and 0 <= nj < w and room[ni][nj] and not visited[ni][nj]: -                visited[ni][nj] = True -                q.append((ni, nj)) -                cnt += 1 -    return cnt +def dfs(w, h, room, i, j): +    if i < 0 or i >= h or j < 0 or j >= w or (room[i][j] == "#"): +        return +    global cnt +    cnt += 1 +    room[i][j] = "#" +    dfs(w, h, room, i + 1, j) +    dfs(w, h, room, i - 1, j) +    dfs(w, h, room, i, j + 1) +    dfs(w, h, room, i, j - 1)