while(n,m=gets.split.map &:to_i)[0]>0
a=(b=[?.*(n+2)])+(1..m).map{?.+gets.tr(?\n,?.)}+b
q=[[c=0,0]]
r=[]
(q[0]||(q=r.uniq;r=[];c+=1;puts a)
x,y=q.shift
[[x,y+1],[x,y-1],[x+1,y],[x-1,y]].map{|i,j|d=a[i][j]
d==?.?(a[i][j]=?-;q<<[i,j]):
d==?#?(a[i][j]=?o;r<<[i,j]):
d==?&?(q=r=[];break):0})while q[0]||r[0]
p c
end