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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  vector<vector<char>> r(h, vector<char>(w));
  rep(i, h) cin >> v[i];
  rep(i, h){
    rep(j, w){
      if(v[i][j] == '#') r[i][j] = '#';
      else{
        int c = 0;
        for(int k = max(0, i-1); k < min(h, i+2); ++k){
          for(int l = max(0, j-1); l < min(w, j+2); ++l){
            if(v[k][l] == '#') ++c;
          }
        }
        r[i][j] = c;
      }
    }
  }
  rep(i, h){
    rep(j, ww) cout << r[i][j];
    cout << endl;
  }
  return 0;
}