Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h,w=map(int,input().split())
a=[input() for i in range(h)]
lis=[[-1 for i in range(w)] for j in range(h)]
q=deque()


for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      q.append((i,j))
      lis[i][j]=0


while q:
  cur=q.popleft()
  i,j=cur[0],cur[1]

  if 0<=i+1<=h-1 and 0<=j<=w-1:
    if lis[i+1][j]==-1:
      lis[i+1][j]=lis[i][j]+1
      q.append((i+1,j))
  
  if 0<=i-1<=h-1 and 0<=j<=w-1:
    if lis[i-1][j]==-1:
      lis[i-1][j]=lis[i][j]+1
      q.append((i-1,j))

  
  if 0<=i<=h-1 and 0<=j+1<=w-1:
    if lis[i][j+1]==-1:
      lis[i][j+1]=lis[i][j]+1
      q.append((i,j+1))
      
  if 0<=i<=h-1 and 0<=cur[1]-1<=w-1:
    if lis[i][j-1]==-1:
      lis[i][j-1]=lis[i][j]+1
      q.append((i,j-1))      
  
print(max(max(l) for l in lis))



Fixed submission:
from collections import deque

h,w=map(int,input().split())
a=[input() for i in range(h)]
lis=[[-1 for i in range(w)] for j in range(h)]
q=deque()


for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      q.append((i,j))
      lis[i][j]=0


while q:
  cur=q.popleft()
  i,j=cur[0],cur[1]

  if 0<=i+1<=h-1 and 0<=j<=w-1:
    if lis[i+1][j]==-1:
      lis[i+1][j]=lis[i][j]+1
      q.append((i+1,j))
  
  if 0<=i-1<=h-1 and 0<=j<=w-1:
    if lis[i-1][j]==-1:
      lis[i-1][j]=lis[i][j]+1
      q.append((i-1,j))

  
  if 0<=i<=h-1 and 0<=j+1<=w-1:
    if lis[i][j+1]==-1:
      lis[i][j+1]=lis[i][j]+1
      q.append((i,j+1))
      
  if 0<=i<=h-1 and 0<=cur[1]-1<=w-1:
    if lis[i][j-1]==-1:
      lis[i][j-1]=lis[i][j]+1
      q.append((i,j-1))      
  
print(max(max(l) for l in lis))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h,w=map(int,input().split())
a=[input() for i in range(h)]
lis=[[-1 for i in range(w)] for j in range(h)]
q=deque()


for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      q.append((i,j))
      lis[i][j]=0


while q:
  cur=q.popleft()

  if 0<=cur[0]+1<=h-1 and 0<=cur[1]<=w-1:
    if lis[cur[0]+1][cur[1]]==-1:
      lis[cur[0]+1][cur[1]]=lis[cur[0]][cur[1]]+1
      q.append((cur[0]+1,cur[1]))
  
  if 0<=cur[0]-1<=h-1 and 0<=cur[1]<=w-1:
    if lis[cur[0]-1][cur[1]]==-1:
      lis[cur[0]-1][cur[1]]=lis[cur[0]][cur[1]]+1
      q.append((cur[0]-1,cur[1]))

  
  if 0<=cur[0]<=h-1 and 0<=cur[1]+1<=w-1:
    if lis[cur[0]][cur[1]+1]==-1:
      lis[cur[0]][cur[1]+1]=lis[cur[0]][cur[1]]+1
      q.append((cur[0],cur[1]+1))
      
  if 0<=cur[0]<=h-1 and 0<=cur[1]-1<=w-1:
    if lis[cur[0]][cur[1]-1]==-1:
      lis[cur[0]][cur[1]-1]=lis[cur[0]][cur[1]]+1
      q.append((cur[0],cur[1]-1))      
  
print(max(max(l) for l in lis))



Fixed submission:
from collections import deque

h,w=map(int,input().split())
a=[input() for i in range(h)]
lis=[[-1 for i in range(w)] for j in range(h)]
q=deque()


for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      q.append((i,j))
      lis[i][j]=0


while q:
  cur=q.popleft()
  i,j=cur[0],cur[1]

  if 0<=i+1<=h-1 and 0<=j<=w-1:
    if lis[i+1][j]==-1:
      lis[i+1][j]=lis[i][j]+1
      q.append((i+1,j))
  
  if 0<=i-1<=h-1 and 0<=j<=w-1:
    if lis[i-1][j]==-1:
      lis[i-1][j]=lis[i][j]+1
      q.append((i-1,j))

  
  if 0<=i<=h-1 and 0<=j+1<=w-1:
    if lis[i][j+1]==-1:
      lis[i][j+1]=lis[i][j]+1
      q.append((i,j+1))
      
  if 0<=i<=h-1 and 0<=cur[1]-1<=w-1:
    if lis[i][j-1]==-1:
      lis[i][j-1]=lis[i][j]+1
      q.append((i,j-1))      
  
print(max(max(l) for l in lis))

Buggy python submission (verdict: Runtime Error):
from collections import deque

h,w=map(int,input().split())
a=[input() for i in range(h)]
lis=[[-1 for i in range(w)] for j in range(h)]
q=deque()


for i in range(w):
  for j in range(h):
    if a[i][j]=="#":
      q.append((i,j))
      lis[i][j]=0


while q:
  cur=q.popleft()

  if 0<=cur[0]+1<=h-1 and 0<=cur[1]<=w-1:
    if lis[cur[0]+1][cur[1]]==-1:
      lis[cur[0]+1][cur[1]]=lis[cur[0]][cur[1]]+1
      q.append((cur[0]+1,cur[1]))
  
  if 0<=cur[0]-1<=h-1 and 0<=cur[1]<=w-1:
    if lis[cur[0]-1][cur[1]]==-1:
      lis[cur[0]-1][cur[1]]=lis[cur[0]][cur[1]]+1
      q.append((cur[0]-1,cur[1]))

  
  if 0<=cur[0]<=h-1 and 0<=cur[1]+1<=w-1:
    if lis[cur[0]][cur[1]+1]==-1:
      lis[cur[0]][cur[1]+1]=lis[cur[0]][cur[1]]+1
      q.append((cur[0],cur[1]+1))
      
  if 0<=cur[0]<=h-1 and 0<=cur[1]-1<=w-1:
    if lis[cur[0]][cur[1]-1]==-1:
      lis[cur[0]][cur[1]-1]=lis[cur[0]][cur[1]]+1
      q.append((cur[0],cur[1]-1))      
  
print(max(max(l) for l in lis))



Fixed submission:
from collections import deque

h,w=map(int,input().split())
a=[input() for i in range(h)]
lis=[[-1 for i in range(w)] for j in range(h)]
q=deque()


for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      q.append((i,j))
      lis[i][j]=0


while q:
  cur=q.popleft()
  i,j=cur[0],cur[1]

  if 0<=i+1<=h-1 and 0<=j<=w-1:
    if lis[i+1][j]==-1:
      lis[i+1][j]=lis[i][j]+1
      q.append((i+1,j))
  
  if 0<=i-1<=h-1 and 0<=j<=w-1:
    if lis[i-1][j]==-1:
      lis[i-1][j]=lis[i][j]+1
      q.append((i-1,j))

  
  if 0<=i<=h-1 and 0<=j+1<=w-1:
    if lis[i][j+1]==-1:
      lis[i][j+1]=lis[i][j]+1
      q.append((i,j+1))
      
  if 0<=i<=h-1 and 0<=cur[1]-1<=w-1:
    if lis[i][j-1]==-1:
      lis[i][j-1]=lis[i][j]+1
      q.append((i,j-1))      
  
print(max(max(l) for l in lis))