var a:array[0..51,0..51]of string;
i,j,n,m,k,l,p:integer;
begin
readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do read(a[i,j]);
readln;
end;
for i:=1 to n do
for j:=1 to m do
begin
p:=0;
if a[i,j]<>'#' then begin
for k:=i-1 to i+1 do
for l:=j-1 to j+1 do
if a[k,l]='#' then p:=p+1;
str(p,a[i,j]);
end;
end;
for i:=1 to n do
begin
for j:=1 to m do write(a[i,j]);
writeln;
end;
end.