#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;

int main(){
  int dx[8]={1,0,-1,0,1,-1,-1,1};
  int dy[8]={0,1,0,-1,1,1,-1,-1};
  
  int h,w;
  cin >> h >> w;
  
  string s[50];
  rep(i,h) cin >> s[i];

  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#') continue;

      int count=0;
      rep(k,8){
	int x = i+dx[k];
	int y = j+dy[k];

	if(x<0 or h<=x) continue;
	if(y<0 or w<=y) continue;
	if(s[x][y] == '#') count++;
      }

      s[i][j] = char('0'+count);
    }
  }

  rep(i,h) cout << s[i] << endl;
  
  return 0;
}
