Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w):
    A[h][w]="#"
    que=[]
    if h>0:
        if A[h-1][w]!="#":
            que.append([h-1,w])
            A[h-1][w]="#"
    if w>0:
        if A[h][w-1]!="#":
            que.append([h,w-1])
            A[h][w-1]="#"
    if h<H-1:
        if A[h+1][w]!="#":
            que.append([h+1,w])
            A[h+1][w]="#"
    if w<W-1:
        if A[h][w+1]!="#":
            que.append([h,w+1])
            A[h][w+1]="#"
    
    return que


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

ans=0
lis=[]
for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            lis.append([h,w])
while True:
    if lis:
        N=len(lis)
        for i in range(N):
            item=lis.pop(0)
            lis+=dfs(item[0],item[1])
    if len(lis)==0:
        break
    ans+=1
    #print(lis)
    #print(A)
    
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w):
    A[h][w]="#"
    que=[]
    if h>0:
        if A[h-1][w]!="#":
            que.append([h-1,w])
            A[h-1][w]="#"
    if w>0:
        if A[h][w-1]!="#":
            que.append([h,w-1])
            A[h][w-1]="#"
    if h<H-1:
        if A[h+1][w]!="#":
            que.append([h+1,w])
            A[h+1][w]="#"
    if w<W-1:
        if A[h][w+1]!="#":
            que.append([h,w+1])
            A[h][w+1]="#"
    
    return que


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

ans=0
lis=[]
for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            lis.append([h,w])
while True:
    pre=[]
    if lis:
        N=len(lis)
        lis=lis[::-1]
        for i in range(N):
            item=lis.pop(-1)
            pre+=dfs(item[0],item[1])
        lis=pre
    if len(lis)==0:
        break
    ans+=1
    #print(lis)
    #print(A)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w,num):
    
    l[h][w]=min(l[h][w],num)
    
    if h>0:
        if A[h-1][w]!="#" and l[h-1][w]>=num:
            dfs(h-1,w,num+1)
    if w>0:
        if A[h][w-1]!="#" and l[h][w-1]>=num:
            dfs(h,w-1,num+1)
    if h<H-1:
        if A[h+1][w]!="#" and l[h+1][w]>=num:
            dfs(h+1,w,num+1)
    if w<W-1:
        if A[h][w+1]!="#" and l[h][w+1]>=num:
            dfs(h,w+1,num+1)
    
    return 0


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

l=[[300]*W for i in range(H)]

for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            dfs(h,w,0)
ans=0
for item in l:
    ans=max(ans,max(item))

#print(l)
print(ans)


Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w):
    A[h][w]="#"
    que=[]
    if h>0:
        if A[h-1][w]!="#":
            que.append([h-1,w])
            A[h-1][w]="#"
    if w>0:
        if A[h][w-1]!="#":
            que.append([h,w-1])
            A[h][w-1]="#"
    if h<H-1:
        if A[h+1][w]!="#":
            que.append([h+1,w])
            A[h+1][w]="#"
    if w<W-1:
        if A[h][w+1]!="#":
            que.append([h,w+1])
            A[h][w+1]="#"
    
    return que


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

ans=0
lis=[]
for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            lis.append([h,w])
while True:
    pre=[]
    if lis:
        N=len(lis)
        lis=lis[::-1]
        for i in range(N):
            item=lis.pop(-1)
            pre+=dfs(item[0],item[1])
        lis=pre
    if len(lis)==0:
        break
    ans+=1
    #print(lis)
    #print(A)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w):
    que=[]
    if h>0:
        if A[h-1][w]!="#":
            que.append([h-1,w])
    if w>0:
        if A[h][w-1]!="#":
            que.append([h,w-1])
    if h<H-1:
        if A[h+1][w]!="#":
            que.append([h+1,w])
    if w<W-1:
        if A[h][w+1]!="#":
            que.append([h,w+1])
    
    return que


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

ans=0
while True:
    lis=[]
    for h in range(H):
        for w in range(W):
            if A[h][w]=="#":
                lis+=dfs(h,w)
    if lis:
        for item in lis:
            A[item[0]][item[1]]="#"
    else:
        break
    ans+=1
    
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w):
    A[h][w]="#"
    que=[]
    if h>0:
        if A[h-1][w]!="#":
            que.append([h-1,w])
            A[h-1][w]="#"
    if w>0:
        if A[h][w-1]!="#":
            que.append([h,w-1])
            A[h][w-1]="#"
    if h<H-1:
        if A[h+1][w]!="#":
            que.append([h+1,w])
            A[h+1][w]="#"
    if w<W-1:
        if A[h][w+1]!="#":
            que.append([h,w+1])
            A[h][w+1]="#"
    
    return que


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

ans=0
lis=[]
for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            lis.append([h,w])
while True:
    pre=[]
    if lis:
        N=len(lis)
        lis=lis[::-1]
        for i in range(N):
            item=lis.pop(-1)
            pre+=dfs(item[0],item[1])
        lis=pre
    if len(lis)==0:
        break
    ans+=1
    #print(lis)
    #print(A)
    
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w,num):
    
    l[h][w]=min(l[h][w],num)
    
    if h>0:
        if A[h-1][w]!="#" and l[h-1][w]>num:
            dfs(h-1,w,num+1)
    if w>0:
        if A[h][w-1]!="#" and l[h][w-1]>num:
            dfs(h,w-1,num+1)
    if h<H-1:
        if A[h+1][w]!="#" and l[h+1][w]>num:
            dfs(h+1,w,num+1)
    if w<W-1:
        if A[h][w+1]!="#" and l[h][w+1]>num:
            dfs(h,w+1,num+1)
    
    return 0


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

l=[[10**9]*W for i in range(H)]

for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            dfs(h,w,0)
ans=0
for item in l:
    ans=max(ans,max(item))

#print(l)
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w):
    A[h][w]="#"
    que=[]
    if h>0:
        if A[h-1][w]!="#":
            que.append([h-1,w])
            A[h-1][w]="#"
    if w>0:
        if A[h][w-1]!="#":
            que.append([h,w-1])
            A[h][w-1]="#"
    if h<H-1:
        if A[h+1][w]!="#":
            que.append([h+1,w])
            A[h+1][w]="#"
    if w<W-1:
        if A[h][w+1]!="#":
            que.append([h,w+1])
            A[h][w+1]="#"
    
    return que


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

ans=0
lis=[]
for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            lis.append([h,w])
while True:
    pre=[]
    if lis:
        N=len(lis)
        lis=lis[::-1]
        for i in range(N):
            item=lis.pop(-1)
            pre+=dfs(item[0],item[1])
        lis=pre
    if len(lis)==0:
        break
    ans+=1
    #print(lis)
    #print(A)
    
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w,num):
    
    l[h][w]=min(l[h][w],num)
    
    if h>0:
        if A[h-1][w]!="#" and l[h-1][w]>num:
            dfs(h-1,w,num+1)
    if w>0:
        if A[h][w-1]!="#" and l[h][w-1]>num:
            dfs(h,w-1,num+1)
    if h<H-1:
        if A[h+1][w]!="#" and l[h+1][w]>num:
            dfs(h+1,w,num+1)
    if w<W-1:
        if A[h][w+1]!="#" and l[h][w+1]>num:
            dfs(h,w+1,num+1)
    
    return 0


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

l=[[10**9]*W for i in range(H)]

for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            dfs(h,w,0)
ans=0
for item in l:
    ans=max(ans,max(item))

#print(l)
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def dfs(h,w):
    A[h][w]="#"
    que=[]
    if h>0:
        if A[h-1][w]!="#":
            que.append([h-1,w])
            A[h-1][w]="#"
    if w>0:
        if A[h][w-1]!="#":
            que.append([h,w-1])
            A[h][w-1]="#"
    if h<H-1:
        if A[h+1][w]!="#":
            que.append([h+1,w])
            A[h+1][w]="#"
    if w<W-1:
        if A[h][w+1]!="#":
            que.append([h,w+1])
            A[h][w+1]="#"
    
    return que


A=[]
for _ in range(H):
    A.append(list(input()))

#print(A)

ans=0
lis=[]
for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            lis.append([h,w])
while True:
    pre=[]
    if lis:
        N=len(lis)
        lis=lis[::-1]
        for i in range(N):
            item=lis.pop(-1)
            pre+=dfs(item[0],item[1])
        lis=pre
    if len(lis)==0:
        break
    ans+=1
    #print(lis)
    #print(A)
    
print(ans)