#include <iostream>
using namespace std;

int main(void){
  char fld[60][60];
  int h,w;
  
  cin >> h >> w;
  for (int i=1; i<=h; i++){
    cin >> (fld[i]+1);
  }
  for (int i=1; i<=h; i++){
    for (int j=1; j<=w; j++){
      int t=0;
      for (int dy=-1; dy<=1; dy++){
        for (int dx=-1; dx<=1; dx++){
          if (fld[i+dy][j+dx]=='#') t++;
        }
      }
      if (fld[i][j]=='.') fld[i][j] = t+'0';
    }
    cout << (fld[i]+1) << endl;
  }
  return 0;
}