H,W=gets.split.map &:to_i M=$<.to_a a=[] H.times{|h|W.times{|w|M[h][w]==?*&&a<<[h,w]}} h,w=[[0,0],[H-1,0],[0,W-1]].find{|e|a.transpose.zip(e).none?{|x,y|x.include?(y)}} M[h][w]=?* puts M