void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int h, w; rd(h, w);
  auto c=new char[][](h, w);
  foreach(i; 0..h) c[i]=readln.chomp.to!(char[]);

  auto dd=[[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]];
  foreach(i; 0..h)foreach(j; 0..w)if(c[i][j]!='#'){
    int cnt=0;
    foreach(d; dd){
      auto ni=i+d[0], nj=j+d[1];
      if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
      if(c[ni][nj]=='#') cnt++;
    }
    c[i][j]=to!char(cnt+'0');
  }

  foreach(i; 0..h) writeln(c[i]);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}