#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int h,w;
  cin >> h >> w;
  
  char c[h+2][w+2];
  
  REP(i,h){
    REP(j,w){
      cin >> char c[i+1][j+1];
    }
  }
  
  int vx[8] = {1,1,1,0,0,-1,-1,-1};
  int vy[8] = {1,0,-1,1,-1,1,0,-1};
  
  char ans[h][w];
  REP(i,h){
    REP(j,w){
      if(c[i+1][j+1] == '#') ans[i][j] = '#';
      else{
        int cnt = 0;
      REP(k,8){
      if(c[i+1+vx[k]][j+1+vy[k]] == '#') cnt++;
      }
        ans[i][j] = (char)cnt + '0';
      }
    }
  }

  REP(i,h){
    REP(j,w){
      cout << ans[i][j];
    }
    cout << endl;
  }

 return 0;
}