Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
g = [[True]*(w+2)]
bp = []
for i in range(h):
    b = []
    for j, a in enumerate(input()):
        if a == '#':
            bp.append((i+1, j+1))
            b.append(True)
        else:
            b.append(False)
    g.append([True] + b + [True])
g.append([True]*(w+2))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append((i+1, j))
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append((i-1, j))       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append((i, j+1))
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append((i, j-1))
    cnt += 1
    bp = p
print(cnt-1)

Fixed submission:
h, w = map(int, input().split())
g = [[True]*(w+2)]
for i in range(h):
    g.append([True] + [a == '#' for a in input()] + [True])
g.append([True]*(w+2))

bp = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if g[i][j]:
            bp.append((i, j))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append((i+1, j))
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append((i-1, j))       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append((i, j+1))
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append((i, j-1))
    cnt += 1
    bp = p
print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
g = [[True]*(w+2)]
for i in range(h):
    g.append([True] + [a == '#' for a in input()] + [True])
g.append([True]*(w+2))

bp = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if g[i][j]:
            bp.append([i, j])

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append([i+1, j])
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append([i-1, j])       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append([i, j+1])
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append([i, j-1])
    cnt += 1
    bp = p
print(cnt-1)

Fixed submission:
h, w = map(int, input().split())
g = [[True]*(w+2)]
for i in range(h):
    g.append([True] + [a == '#' for a in input()] + [True])
g.append([True]*(w+2))

bp = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if g[i][j]:
            bp.append((i, j))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append((i+1, j))
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append((i-1, j))       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append((i, j+1))
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append((i, j-1))
    cnt += 1
    bp = p
print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
g = [[True]*(w+2)]
for i in range(h):
    b = []
    for a in input():
        if a == '#':
            b.append(True)
        else:
            b.append(False)
    g.append([True] + b + [True])
g.append([True]*(w+2))

bp = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if g[i][j]:
            bp.append([i, j])

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append([i+1, j])
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append([i-1, j])       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append([i, j+1])
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append([i, j-1])
    cnt += 1
    bp = p
print(cnt-1)

Fixed submission:
h, w = map(int, input().split())
g = [[True]*(w+2)]
for i in range(h):
    g.append([True] + [a == '#' for a in input()] + [True])
g.append([True]*(w+2))

bp = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if g[i][j]:
            bp.append((i, j))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append((i+1, j))
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append((i-1, j))       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append((i, j+1))
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append((i, j-1))
    cnt += 1
    bp = p
print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
g = [[True]*(w+2)]
bp = []
for i in range(h):
    A = input()
    b = [False]*w
    for j, a in enumerate(A):
        if a == '#':
            bp.append([i+1, j+1])
            b[j] = True
    g.append([True] + b + [True])
g.append([True]*(w+2))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append([i+1, j])
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append([i-1, j])       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append([i, j+1])
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append([i, j-1])
    cnt += 1
    bp = p
print(cnt-1)

Fixed submission:
h, w = map(int, input().split())
g = [[True]*(w+2)]
for i in range(h):
    g.append([True] + [a == '#' for a in input()] + [True])
g.append([True]*(w+2))

bp = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if g[i][j]:
            bp.append((i, j))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append((i+1, j))
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append((i-1, j))       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append((i, j+1))
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append((i, j-1))
    cnt += 1
    bp = p
print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
g = [[True]*(w+2)]
bp = []
for i in range(h):
    A = input()
    b = [False]*w
    for j, a in enumerate(A):
        if a == '#':
            bp += [[i+1, j+1]]
            b[j] = True
    g += [[True] + b + [True]]
g += [[True]*(w+2)]

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p += [[i+1, j]]
        if not g[i-1][j]:
            g[i-1][j] = True
            p += [[i-1, j]]        
        if not g[i][j+1]:
            g[i][j+1] = True
            p += [[i, j+1]]
        if not g[i][j-1]:
            g[i][j-1] = True
            p += [[i, j-1]]
    cnt += 1
    bp = p
print(cnt-1)

Fixed submission:
h, w = map(int, input().split())
g = [[True]*(w+2)]
for i in range(h):
    g.append([True] + [a == '#' for a in input()] + [True])
g.append([True]*(w+2))

bp = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if g[i][j]:
            bp.append((i, j))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append((i+1, j))
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append((i-1, j))       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append((i, j+1))
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append((i, j-1))
    cnt += 1
    bp = p
print(cnt-1)