Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = list(map(int, input().split(' ')))
FIELD = list()
for _ in range(H):
    FIELD.append(input())
removal_cell_flag = [[1 if FIELD[h][w] == '.' else 0 for w in range(W)] for h in range(H)]
sh, sw = 0, 0  # start
gh, gw = H - 1, W - 1  # goal
# We can get the maximum score
# when we change colors of cells which are not on the shortest path.
frontier = deque()
ch, cw = sh, sw
frontier.append((ch, cw))
explored_flag = [[0 for _ in range(W)] for _ in range(H)]
parent_table = [[None for _ in range(W)] for _ in range(H)]
while len(frontier) > 0:
    ch, cw = frontier.popleft()  # current
    if ch == gh and cw == gw:  # reach goal
        break
    explored_flag[ch][cw] = 1
    for dh, dw in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = ch + dh, cw + dw  # next
        if (nh < 0) or (H - 1 < nh) or (nw < 0) or (W - 1 < nw):
            continue
        if FIELD[nh][nw] == '#':
            continue
        if explored_flag[nh][nw] == 1:
            continue
        parent_table[nh][nw] = (ch, cw)
        frontier.append((nh, nw))
if ch != gh and cw != gw:
    print(-1)
    exit(0)
while True:
    removal_cell_flag[ch][cw] = 0
    if parent_table[ch][cw] is None:
        break
    ch, cw = parent_table[ch][cw]
print(sum([sum(row) for row in removal_cell_flag]))

Fixed submission:
from collections import deque
H, W = list(map(int, input().split(' ')))
FIELD = list()
for _ in range(H):
    FIELD.append(input())
WHITE_CELL_NUM = 0
for h in range(H):
    for w in range(W):
        if FIELD[h][w] == '.':
            WHITE_CELL_NUM += 1
sh, sw = 0, 0  # start
gh, gw = H - 1, W - 1  # goal
# We can get the maximum score
# when we change colors of cells which are not on the shortest path.
frontier = deque()
ch, cw = sh, sw
frontier.append((ch, cw))
steps = [[-1 for _ in range(W)] for _ in range(H)]
steps[ch][cw] = 0
while len(frontier) > 0:
    ch, cw = frontier.popleft()  # current
    if ch == gh and cw == gw:  # reach goal
        break
    for dh, dw in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = ch + dh, cw + dw  # next
        if (nh < 0) or (H - 1 < nh) or (nw < 0) or (W - 1 < nw):
            continue
        if FIELD[nh][nw] == '#':
            continue
        if steps[nh][nw] >= 0:
            continue
        steps[nh][nw] = steps[ch][cw] + 1
        frontier.append((nh, nw))
if ch != gh and cw != gw:
    print(-1)
    exit(0)
shortest_path_length = steps[gh][gw] + 1
print(WHITE_CELL_NUM - shortest_path_length)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = list(map(int, input().split(' ')))
FIELD = list()
for _ in range(H):
    FIELD.append(input())
removal_cell_flag = [[1 if FIELD[h][w] == '.' else 0 for w in range(W)] for h in range(H)]
class Node:
    def __init__(self, h, w):
        self.h = h
        self.w = w
        self.parent = None
sh, sw = 0, 0  # start
gh, gw = H - 1, W - 1  # goal
# We can get the maximum score
# when we change colors of cells which are not on the shortest path.
frontier = deque()
frontier.append(Node(sh, sw))
explored_flag = [[0 for _ in range(W)] for _ in range(H)]
node = None
while len(frontier) > 0:
    node = frontier.popleft()
    if node.h == gh and node.w == gw:  # reach goal
        break
    explored_flag[node.h][node.w] = 1
    for dh, dw in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = node.h + dh, node.w + dw  # next
        if (nh < 0) or (H - 1 < nh) or (nw < 0) or (W - 1 < nw):
            continue
        if FIELD[nh][nw] == '#':
            continue
        if explored_flag[nh][nw] == 1:
            continue
        next_node = Node(nh, nw)
        next_node.parent = node
        frontier.append(next_node)
if node.h != gh and node.w != gw:
    print(-1)
    exit(0)
while True:
    removal_cell_flag[node.h][node.w] = 0
    if node.parent is None:
        break
    node = node.parent
print(sum([sum(row) for row in removal_cell_flag]))

Fixed submission:
from collections import deque
H, W = list(map(int, input().split(' ')))
FIELD = list()
for _ in range(H):
    FIELD.append(input())
WHITE_CELL_NUM = 0
for h in range(H):
    for w in range(W):
        if FIELD[h][w] == '.':
            WHITE_CELL_NUM += 1
sh, sw = 0, 0  # start
gh, gw = H - 1, W - 1  # goal
# We can get the maximum score
# when we change colors of cells which are not on the shortest path.
frontier = deque()
ch, cw = sh, sw
frontier.append((ch, cw))
steps = [[-1 for _ in range(W)] for _ in range(H)]
steps[ch][cw] = 0
while len(frontier) > 0:
    ch, cw = frontier.popleft()  # current
    if ch == gh and cw == gw:  # reach goal
        break
    for dh, dw in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = ch + dh, cw + dw  # next
        if (nh < 0) or (H - 1 < nh) or (nw < 0) or (W - 1 < nw):
            continue
        if FIELD[nh][nw] == '#':
            continue
        if steps[nh][nw] >= 0:
            continue
        steps[nh][nw] = steps[ch][cw] + 1
        frontier.append((nh, nw))
if ch != gh and cw != gw:
    print(-1)
    exit(0)
shortest_path_length = steps[gh][gw] + 1
print(WHITE_CELL_NUM - shortest_path_length)