Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10000)

H, W = map(int, input().split())
##計算の都合、 通路(.)を正の整数、壁(#)を-1に変換する
Mij = [[0] * W for _ in range(H)]
space_count = 0
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == ".":
            space_count += 1
            Mij[i][j] = 100000
        else:
            Mij[i][j] = -1

dirs = [[1, 0], [0, 1], [-1, 0], [0, -1]]

def search(i, j, step):
    if i == H - 1 and j == W - 1:
        return step

    best = None
    for d in dirs:
        i2 = i + d[0]
        j2 = j + d[1]
        if 0 <= i2 < H and 0 <= j2 < W:
            if step + 1 < Mij[i2][j2]:
                Mij[i2][j2] = step
                r = search(i2, j2, step + 1)
                if not r:
                    continue
                if not best or best > r:
                    best = r
    return best

total_steps = search(0, 0, 1)
if total_steps is None:
    print(-1)
else:
    print(space_count - total_steps)


Fixed submission:
H, W = map(int, input().split())
##計算の都合、 通路(.)を正の整数、壁(#)を-1に変換する
LARGE_VALUE = 100000
Mij = [[0] * W for _ in range(H)]
space_count = 0
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == ".":
            space_count += 1
            Mij[i][j] = LARGE_VALUE
        else:
            Mij[i][j] = -1

dirs = [[1, 0], [0, 1], [-1, 0], [0, -1]]

queue = [[0, 0]]

def search():
    while len(queue):
        p = queue[0]
        del queue[0]
        i = p[0]
        j = p[1]
        step = Mij[i][j]

        for d in dirs:
            i2 = i + d[0]
            j2 = j + d[1]
            if 0 <= i2 < H and 0 <= j2 < W:
                if step + 1 < Mij[i2][j2]:
                    Mij[i2][j2] = step + 1
                    queue.append([i2, j2])

Mij[0][0] = 1
search()
total_steps = Mij[H - 1][W - 1]
if total_steps == LARGE_VALUE:
    print(-1)
else:
    print(space_count - total_steps)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
##計算の都合、 通路(.)を正の整数、壁(#)を-1に変換する
Mij = [[0] * W for _ in range(H)]
space_count = 0
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == ".":
            space_count += 1
            Mij[i][j] = 100000
        else:
            Mij[i][j] = -1

dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]

def search(i, j, step):
    if i == H - 1 and j == W - 1:
        return step

    best = None
    for d in dirs:
        i2 = i + d[0]
        j2 = j + d[1]
        if 0 <= i2 < H and 0 <= j2 < W:
            if step + 1 < Mij[i2][j2]:
                Mij[i2][j2] = step
                r = search(i2, j2, step + 1)
                if not r:
                    continue
                if not best or best > r:
                    best = r
    return best

total_steps = search(0, 0, 1)
if total_steps is None:
    print(-1)
else:
    print(space_count - total_steps)


Fixed submission:
H, W = map(int, input().split())
##計算の都合、 通路(.)を正の整数、壁(#)を-1に変換する
LARGE_VALUE = 100000
Mij = [[0] * W for _ in range(H)]
space_count = 0
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == ".":
            space_count += 1
            Mij[i][j] = LARGE_VALUE
        else:
            Mij[i][j] = -1

dirs = [[1, 0], [0, 1], [-1, 0], [0, -1]]

queue = [[0, 0]]

def search():
    while len(queue):
        p = queue[0]
        del queue[0]
        i = p[0]
        j = p[1]
        step = Mij[i][j]

        for d in dirs:
            i2 = i + d[0]
            j2 = j + d[1]
            if 0 <= i2 < H and 0 <= j2 < W:
                if step + 1 < Mij[i2][j2]:
                    Mij[i2][j2] = step + 1
                    queue.append([i2, j2])

Mij[0][0] = 1
search()
total_steps = Mij[H - 1][W - 1]
if total_steps == LARGE_VALUE:
    print(-1)
else:
    print(space_count - total_steps)