#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  string masu[20];
  for (int i = 0; i < h; i++) {
    cin >> masu[i];
  }
  int x[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int y[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (masu[i][j] == '#') continue;
      int num = 0;
      for (int k = 0; k < 8; k++) {
        int nx = i - x[k];
        int ny = j - y[k];
        if (nx < 0 || h <= nx) continue;
        if (ny < 0 || w <= ny) continue;
        if (masu[nx][ny] == '#') num++;
      }
      masu[i][j] = char(num + '0');
    }
  }
  for (int i = 0; i < h; i++) cout << masu[i] << endl;
}
