#include <bits/stdc++.h>
using namespace std;

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

  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(brd[i][j] == '#') continue;
      int num = 0;
      for(int d = 0; d < 8; d++) {
        int ni = i + dy[d];
        int nj = j + dx[d];

        if(ni < 0 || h <= hi) continue;
        if(nj < 0 || w <= nj) continue;
        if(brd[ni][nj] == '#') num++;
      }
      brd[i][j] = char(num + '0');
      for(int i = 0; i < h; i++) {
        cout << brd[i] << endl;
      }
    }
  }
  return 0;
}
