var x:char;h,w,i,j:longint;a:array[0..50,0..50]of 0..1;
begin
 readln(h,w);
 for i:=1 to h do
  begin
   for j:=1 to w do
    begin
     read(x);
     if(x='#')then a[i,j]:=1;
    end;readln;
  end;
 for i:=1 to h do
  begin
   for j:=1 to w do
    if a[i,j]=1 then write('#')
                else write(a[i-1,j-1]+a[i-1,j]+a[i-1,j+1]+a[i,j-1]+a[i,j+1]+a[i+1,j-1]+a[i+1,j]+a[i+1,j+1]);
   writeln;
  end;
end.