Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)




Fixed submission:
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			new=True
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while new:
	p=0
	black_new=[]
	new=False
	black.sort()
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if p>=q:
			break
		if [i,j]==black[p]:
			p+=1
			if i!=0 and field[i-1][j]==False:
				field[i-1][j]=True
				black_new.append([i-1,j])
				new=True
			if i!=h-1 and field[i+1][j]==False:
				field[i+1][j]=True
				black_new.append([i+1,j])
				new=True
			if j!=0 and field[i][j-1]==False:
				field[i][j-1]=True
				black_new.append([i,j-1])
				new=True
			if j!=w-1 and field[i][j+1]==False:
				field[i][j+1]=True
				black_new.append([i,j+1])
				new=True
	black=black_new
	ans+=1
print(ans-1)




Fixed submission:
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			new=True
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while new:
	p=0
	black_new=[]
	new=False
	black.sort()
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if p>=q:
			break
		if [i,j]==black[p]:
			p+=1
			if i!=0 and field[i-1][j]==False:
				field[i-1][j]=True
				black_new.append([i-1,j])
				new=True
			if i!=h-1 and field[i+1][j]==False:
				field[i+1][j]=True
				black_new.append([i+1,j])
				new=True
			if j!=0 and field[i][j-1]==False:
				field[i][j-1]=True
				black_new.append([i,j-1])
				new=True
			if j!=w-1 and field[i][j+1]==False:
				field[i][j+1]=True
				black_new.append([i,j+1])
				new=True
	black=black_new
	ans+=1
print(ans-1)




Fixed submission:
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			new=True
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while new:
	p=0
	black_new=[]
	new=False
	black.sort()
	q=len(black)
	for i in range(h):
		for j in range(w):
			if p>=q:
				break
			if [i,j]==black[p]:
				p+=1
				if i!=0 and field[i-1][j]==False:
					field[i-1][j]=True
					black_new.append([i-1,j])
					new=True
				if i!=h-1 and field[i+1][j]==False:
					field[i+1][j]=True
					black_new.append([i+1,j])
					new=True
				if j!=0 and field[i][j-1]==False:
					field[i][j-1]=True
					black_new.append([i,j-1])
					new=True
				if j!=w-1 and field[i][j+1]==False:
					field[i][j+1]=True
					black_new.append([i,j+1])
					new=True
	black=black_new
	ans+=1
print(ans-1)




Fixed submission:
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			new=True
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while new:
	p=0
	black_new=[]
	new=False
	black.sort()
	for i in range(h):
		for j in range(w):
			if p>=len(black):
				break
			if [i,j]==black[p]:
				p+=1
				if i!=0 and field[i-1][j]==False:
					field[i-1][j]=True
					black_new.append([i-1,j])
					new=True
				if i!=h-1 and field[i+1][j]==False:
					field[i+1][j]=True
					black_new.append([i+1,j])
					new=True
				if j!=0 and field[i][j-1]==False:
					field[i][j-1]=True
					black_new.append([i,j-1])
					new=True
				if j!=w-1 and field[i][j+1]==False:
					field[i][j+1]=True
					black_new.append([i,j+1])
					new=True
	black=black_new
	ans+=1
print(ans-1)




Fixed submission:
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			new=True
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while new:
	p=0
	black_new=[]
	new=False
	black.sort()
	for i in range(h):
		for j in range(w):
			if p>=len(black):
				break
			if [i,j]==black[p]:
				p+=1
				if i!=0 and field[i-1][j]==False:
					field[i-1][j]=True
					black_new.append([i-1,j])
					new=True
				if i!=h-1 and field[i+1][j]==False:
					field[i+1][j]=True
					black_new.append([i+1,j])
					new=True
				if j!=0 and field[i][j-1]==False:
					field[i][j-1]=True
					black_new.append([i,j-1])
					new=True
				if j!=w-1 and field[i][j+1]==False:
					field[i][j+1]=True
					black_new.append([i,j+1])
					new=True
	black=black_new
	ans+=1
print(ans-1)




Fixed submission:
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			new=True
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while new:
	black_new=[]
	new=False
	for i in range(h):
		for j in range(w):
			if [i,j] in black:
				if i!=0 and field[i-1][j]==False:
					field[i-1][j]=True
					black_new.append([i-1,j])
					new=True
				if i!=h-1 and field[i+1][j]==False:
					field[i+1][j]=True
					black_new.append([i+1,j])
					new=True
				if j!=0 and field[i][j-1]==False:
					field[i][j-1]=True
					black_new.append([i,j-1])
					new=True
				if j!=w-1 and field[i][j+1]==False:
					field[i][j+1]=True
					black_new.append([i,j+1])
					new=True
	black=black_new
	ans+=1
print(ans-1)




Fixed submission:
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			new=True
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while new:
	black_new=[]
	new=False
	for i in range(h):
		for j in range(w):
			if [i,j] in black:
				if i!=0 and field[i-1][j]==False:
					field[i-1][j]=True
					black_new.append([i-1,j])
					new=True
				if i!=h-1 and field[i+1][j]==False:
					field[i+1][j]=True
					black_new.append([i+1,j])
					new=True
				if j!=0 and field[i][j-1]==False:
					field[i][j-1]=True
					black_new.append([i,j-1])
					new=True
				if j!=w-1 and field[i][j+1]==False:
					field[i][j+1]=True
					black_new.append([i,j+1])
					new=True
	black=black_new
	ans+=1
print(ans-1)




Fixed submission:
h,w=map(int,input().split())
field=[]
new=False
black=[]
for i in range(h):
	b=[]
	a=input()
	for j in range(w):
		if a[j]=="#":
			b.append(1)
			black.append([i,j])
		else:
			b.append(0)
	field.append(b)
ans=0
while len(black):
	black_new=[]
	q=len(black)
	for k in range(q):
		i,j=black[k][0],black[k][1]
		if i!=0 and field[i-1][j]==False:
			field[i-1][j]=True
			black_new.append([i-1,j])
		if i!=h-1 and field[i+1][j]==False:
			field[i+1][j]=True
			black_new.append([i+1,j])
		if j!=0 and field[i][j-1]==False:
			field[i][j-1]=True
			black_new.append([i,j-1])
		if j!=w-1 and field[i][j+1]==False:
			field[i][j+1]=True
			black_new.append([i,j+1])
	black=black_new
	ans+=1
print(ans-1)