Buggy python submission (verdict: Time Limit Exceeded):
import collections
def bfs(G,l):
    l.append([1,1])
    visited = [[0] * len(G[0]) for i in range(len(G))]
    chk = 0
    G[1][1] = 0
    while(len(l)):
        now = l.popleft()
        visited[now[0]][now[1]] = 1
        if now == [len(G)-2,len(G[0])-2]:
            chk = 1
            break

        if G[now[0]][now[1]+1] != "#" and visited[now[0]][now[1]+1] == 0:
            l.append([now[0],now[1]+1])
            G[now[0]][now[1]+1] = min(G[now[0]][now[1]] + 1,G[now[0]][now[1]+1])

        if G[now[0]][now[1]-1] != "#" and visited[now[0]][now[1]-1] == 0:
            l.append([now[0],now[1]-1])
            G[now[0]][now[1]-1] = min(G[now[0]][now[1]] + 1,G[now[0]][now[1]-1])

        if G[now[0]+1][now[1]] != "#" and visited[now[0]+1][now[1]] == 0:
            l.append([now[0]+1,now[1]])
            G[now[0]+1][now[1]] = min(G[now[0]][now[1]] + 1,G[now[0]+1][now[1]])

        if G[now[0]-1][now[1]] != "#" and visited[now[0]-1][now[1]] == 0:
            l.append([now[0]-1,now[1]])
            G[now[0]-1][now[1]] = min(G[now[0]][now[1]]+1,G[now[0]-1][now[1]])
    return chk

[h,w] = [int(i) for i in input().split()]
s = [["#"] * (w+2)]
whites = 0
for i in range(h):
    ls = ["#"]
    tmp = input()
    for j in range(len(tmp)):
        if tmp[j] == ".":
            ls.append(200)
        else:
            ls.append(tmp[j])
    ls.append("#")
    whites += tmp.count(".")
    s.append(ls)
s.append(["#"] * (w+2))
l = collections.deque()

if bfs(s,l):
    print(whites - s[h][w]-1)
    
else:
    print(-1)
#print(s)


Fixed submission:
import collections
import time
def bfs(G,l):
    l.append([1,1])
    visited = [[0] * len(G[0]) for i in range(len(G))]
    chk = 0
    G[1][1] = 0
    while(len(l)):
        [n0,n1] = l.popleft()
        if visited[n0][n1] == 1:
            continue
        else:
            visited[n0][n1] = 1
        if [n0,n1] == [len(G)-2,len(G[0])-2]:
            chk = 1
            break
        if G[n0][n1+1] != "#" and visited[n0][n1+1] == 0:
            l.append([n0,n1+1])
            G[n0][n1+1] = min(G[n0][n1] + 1,G[n0][n1+1])

        if G[n0][n1-1] != "#" and visited[n0][n1-1] == 0:
            l.append([n0,n1-1])
            G[n0][n1-1] = min(G[n0][n1] + 1,G[n0][n1-1])

        if G[n0+1][n1] != "#" and visited[n0+1][n1] == 0:
            l.append([n0+1,n1])
            G[n0+1][n1] = min(G[n0][n1]+1,G[n0+1][n1])

        if G[n0-1][n1] != "#" and visited[n0-1][n1] == 0:
            l.append([n0-1,n1])
            G[n0-1][n1] = min(G[n0][n1]+1,G[n0-1][n1])
        #print(n0,n1)
    return chk

[h,w] = [int(i) for i in input().split()]
st = time.time()
s = [["#"] * (w+2)]
whites = 0
for i in range(h):
    ls = ["#"]
    tmp = input()
    for j in range(len(tmp)):
        if tmp[j] == ".":
            ls.append(200)
        else:
            ls.append(tmp[j])
    ls.append("#")
    whites += tmp.count(".")
    s.append(ls)
s.append(["#"] * (w+2))
l = collections.deque()
#print(time.time() - st)
if bfs(s,l):
    print(whites - s[h][w]-1)

else:
    print(-1)
#print(time.time() - st)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def bfs(G,l):
    l.append([1,1])
    visited = [[0] * len(G[0]) for i in range(len(G))]
    chk = 0
    G[1][1] = 0
    while(len(l)):
        now = l.popleft()
        visited[now[0]][now[1]] = 1
        if now == [len(G)-2,len(G[0])-2]:
            chk = 1
            break

        if G[now[0]][now[1]+1] != "#" and visited[now[0]][now[1]+1] == 0:
            l.append([now[0],now[1]+1])
            G[now[0]][now[1]+1] = min(G[now[0]][now[1]] + 1,G[now[0]][now[1]+1])

        if G[now[0]][now[1]-1] != "#" and visited[now[0]][now[1]-1] == 0:
            l.append([now[0],now[1]-1])
            G[now[0]][now[1]-1] = min(G[now[0]][now[1]] + 1,G[now[0]][now[1]-1])

        if G[now[0]+1][now[1]] != "#" and visited[now[0]+1][now[1]] == 0:
            l.append([now[0]+1,now[1]])
            G[now[0]+1][now[1]] = min(G[now[0]][now[1]] + 1,G[now[0]+1][now[1]])

        if G[now[0]-1][now[1]] != "#" and visited[now[0]-1][now[1]] == 0:
            l.append([now[0]-1,now[1]])
            G[now[0]-1][now[1]] = min(G[now[0]][now[1]]+1,G[now[0]-1][now[1]])
    return chk

[h,w] = [int(i) for i in input().split()]
s = [["#"] * (w+2)]
whites = 0
for i in range(h):
    ls = ["#"]
    tmp = input()
    for j in range(len(tmp)):
        if tmp[j] == ".":
            ls.append(200)
        else:
            ls.append(tmp[j])
    ls.append("#")
    whites += tmp.count(".")
    s.append(ls)
s.append(["#"] * (w+2))
l = collections.deque()

if bfs(s,l):
    print(whites - s[h][w]-1)
    
else:
    print(-1)
#print(s)


Fixed submission:
import collections
import time
def bfs(G,l):
    l.append([1,1])
    visited = [[0] * len(G[0]) for i in range(len(G))]
    chk = 0
    G[1][1] = 0
    while(len(l)):
        [n0,n1] = l.popleft()
        if visited[n0][n1] == 1:
            continue
        else:
            visited[n0][n1] = 1
        if [n0,n1] == [len(G)-2,len(G[0])-2]:
            chk = 1
            break
        if G[n0][n1+1] != "#" and visited[n0][n1+1] == 0:
            l.append([n0,n1+1])
            G[n0][n1+1] = min(G[n0][n1] + 1,G[n0][n1+1])

        if G[n0][n1-1] != "#" and visited[n0][n1-1] == 0:
            l.append([n0,n1-1])
            G[n0][n1-1] = min(G[n0][n1] + 1,G[n0][n1-1])

        if G[n0+1][n1] != "#" and visited[n0+1][n1] == 0:
            l.append([n0+1,n1])
            G[n0+1][n1] = min(G[n0][n1]+1,G[n0+1][n1])

        if G[n0-1][n1] != "#" and visited[n0-1][n1] == 0:
            l.append([n0-1,n1])
            G[n0-1][n1] = min(G[n0][n1]+1,G[n0-1][n1])
        #print(n0,n1)
    return chk

[h,w] = [int(i) for i in input().split()]
st = time.time()
s = [["#"] * (w+2)]
whites = 0
for i in range(h):
    ls = ["#"]
    tmp = input()
    for j in range(len(tmp)):
        if tmp[j] == ".":
            ls.append(200)
        else:
            ls.append(tmp[j])
    ls.append("#")
    whites += tmp.count(".")
    s.append(ls)
s.append(["#"] * (w+2))
l = collections.deque()
#print(time.time() - st)
if bfs(s,l):
    print(whites - s[h][w]-1)

else:
    print(-1)
#print(time.time() - st)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def bfs(G,l):
    l.append([1,1])
    visited = [[0] * len(G[0]) for i in range(len(G))]
    chk = 0
    G[1][1] = 0
    while(len(l)):
        now = l.popleft()
        visited[now[0]][now[1]] = 1
        if now == [len(G)-2,len(G[0])-2]:
            chk = 1

        if G[now[0]][now[1]+1] != "#" and visited[now[0]][now[1]+1] == 0:
            l.append([now[0],now[1]+1])
            G[now[0]][now[1]+1] = min(G[now[0]][now[1]] + 1,G[now[0]][now[1]+1])

        if G[now[0]][now[1]-1] != "#" and visited[now[0]][now[1]-1] == 0:
            l.append([now[0],now[1]-1])
            G[now[0]][now[1]-1] = min(G[now[0]][now[1]] + 1,G[now[0]][now[1]-1])

        if G[now[0]+1][now[1]] != "#" and visited[now[0]+1][now[1]] == 0:
            l.append([now[0]+1,now[1]])
            G[now[0]+1][now[1]] = min(G[now[0]][now[1]] + 1,G[now[0]+1][now[1]])

        if G[now[0]-1][now[1]] != "#" and visited[now[0]-1][now[1]] == 0:
            l.append([now[0]-1,now[1]])
            G[now[0]-1][now[1]] = min(G[now[0]][now[1]]+1,G[now[0]-1][now[1]])
    return chk

[h,w] = [int(i) for i in input().split()]
s = [["#"] * (w+2)]
whites = 0
for i in range(h):
    ls = ["#"]
    tmp = input()
    for j in range(len(tmp)):
        if tmp[j] == ".":
            ls.append(200)
        else:
            ls.append(tmp[j])
    ls.append("#")
    whites += tmp.count(".")
    s.append(ls)
s.append(["#"] * (w+2))
l = collections.deque()

if bfs(s,l):
    print(whites - s[h][w]-1)
    """
    for i in range(h+2):
        for j in range(w+2):
            print(s[i][j],end = ",")
        print()
    """
else:
    print(-1)
#print(s)


Fixed submission:
import collections
import time
def bfs(G,l):
    l.append([1,1])
    visited = [[0] * len(G[0]) for i in range(len(G))]
    chk = 0
    G[1][1] = 0
    while(len(l)):
        [n0,n1] = l.popleft()
        if visited[n0][n1] == 1:
            continue
        else:
            visited[n0][n1] = 1
        if [n0,n1] == [len(G)-2,len(G[0])-2]:
            chk = 1
            break
        if G[n0][n1+1] != "#" and visited[n0][n1+1] == 0:
            l.append([n0,n1+1])
            G[n0][n1+1] = min(G[n0][n1] + 1,G[n0][n1+1])

        if G[n0][n1-1] != "#" and visited[n0][n1-1] == 0:
            l.append([n0,n1-1])
            G[n0][n1-1] = min(G[n0][n1] + 1,G[n0][n1-1])

        if G[n0+1][n1] != "#" and visited[n0+1][n1] == 0:
            l.append([n0+1,n1])
            G[n0+1][n1] = min(G[n0][n1]+1,G[n0+1][n1])

        if G[n0-1][n1] != "#" and visited[n0-1][n1] == 0:
            l.append([n0-1,n1])
            G[n0-1][n1] = min(G[n0][n1]+1,G[n0-1][n1])
        #print(n0,n1)
    return chk

[h,w] = [int(i) for i in input().split()]
st = time.time()
s = [["#"] * (w+2)]
whites = 0
for i in range(h):
    ls = ["#"]
    tmp = input()
    for j in range(len(tmp)):
        if tmp[j] == ".":
            ls.append(200)
        else:
            ls.append(tmp[j])
    ls.append("#")
    whites += tmp.count(".")
    s.append(ls)
s.append(["#"] * (w+2))
l = collections.deque()
#print(time.time() - st)
if bfs(s,l):
    print(whites - s[h][w]-1)

else:
    print(-1)
#print(time.time() - st)