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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> mine(h+2, vector<char>(w+2, '.'));
  rep(i,h) rep(j,w) cin >> mine[i+1][j+1];
  
  rep(i,h) {
    rep(j,w) {
      if (mine[i+1][j+1] == '#') {
        cout << '#';
        continue;
      }

      int count = 0;
      rep(a,3) rep(b,3) if (mine[i+a][j+b] == '#') count++;
      cout << count;
    }
    cout << endl;
  }
  return 0;
}
