Buggy python submission (verdict: Time Limit Exceeded):
import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#':
                continue
            if dist[nx][ny] > dist[x][y] :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

print(solve())


Fixed submission:
import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#' :
                continue
            if dist[nx][ny] > dist[x][y] + 1 :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

if __name__ == '__main__':
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#':
                continue
            if dist[nx][ny] > dist[x][y] :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

print(solve())


Fixed submission:
import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#' :
                continue
            if dist[nx][ny] > dist[x][y] + 1 :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

if __name__ == '__main__':
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())

field = [input() for _ in range(h)]

dist = [[h*w*100 for i in range(w)] for j in range(h)]
dist[0][0] = 1

import queue

q = queue.Queue()
q.put((0,0))

dx = [-1,1,0,0]
dy = [0,0,1,-1]
while not q.empty() :
    (x,y) = q.get()
    for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
        nx = x + dx
        ny = y + dy
        if nx < 0 or nx >= h or ny < 0 or ny>= w :
            continue
        if field[nx][ny] == '#':
            continue
        if dist[nx][ny] > dist[x][y] :
            dist[nx][ny] = dist[x][y] + 1
            q.put((nx,ny))

if dist[h-1][w-1] >= h*w :
    print(-1)
    exit(0)

# print(dist)

ans = h*w - dist[h-1][w-1]
for v in field:
    for c in v:
        if c == '#':
            ans -= 1

print(ans)


Fixed submission:
import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#' :
                continue
            if dist[nx][ny] > dist[x][y] + 1 :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

if __name__ == '__main__':
    print(solve())