n,m,i,j:longint;
a:array[0..101,0..101]of char;
b:array[0..101,0..101]of longint;
begin
readln(m,n);
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
if a[i,j]='#' then begin
b[i,j]:=1000;
if b[i,j-1]<>1000 then inc(b[i,j-1]);
if b[i,j+1]<>1000 then inc(b[i,j+1]);
if b[i-1,j]<>1000 then inc(b[i-1,j]);
if b[i+1,j]<>1000 then inc(b[i+1,j]);
if b[i-1,j-1]<>1000 then inc(b[i-1,j-1]);
if b[i-1,j+1]<>1000 then inc(b[i-1,j+1]);
if b[i+1,j-1]<>1000 then inc(b[i+1,j-1]);
if b[i+1,j+1]<>1000 then inc(b[i+1,j+1]);
end;
end;
for i:=1 to n do begin
for j:=1 to m do
if b[i,j]=1000 then writeln('#')
else writeln(b[i,j]);
writeln;
end;
end.