#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, i, j;
  string tmp;
  int M[50][50] = {}, N[50][50] = {};
  cin >> H >> W;
  for (i = 0; i < H; ++i) {
    cin >> tmp;
    for (j = 0; j < W; ++j) {
      if (tmp[j] == '.')
        M[i][j] = 0;
      else
        M[i][j] = 1;
    }
  }
  for (i = 0; i < H; ++i) {
    for (j = 0; j < W; ++j) {
      if (i == 0) {
        if (j == 0)
          N[i][j] = M[i][j] + M[1][0] + M[1][1];
        else if (j == W - 1)
          N[i][j] = M[i][j - 1] + M[i + 1][j - 1] + M[i + 1][j];
        else
          N[i][j] = M[i][j - 1] + M[i + 1][j - 1] + M[i + 1][j] +
                    M[i + 1][j + 1] + M[i][j + 1];
      } else if (i == H - 1) {
        if (j == 0)
          N[i][j] = M[i - 1][j] + M[i - 1][j + 1] + M[i][j + 1];
        else if (j == W - 1)
          N[i][j] = M[i - 1][j - 1] + M[i - 1][j] + M[i][j - 1];
        else
          N[i][j] = M[i - 1][j - 1] + M[i][j - 1] + M[i - 1][j] + M[i][j + 1] +
                    M[i - 1][j + 1];
      } else {
        N[i][j] = M[i - 1][j - 1] + M[i - 1][j] + M[i - 1][j + 1] +
                  M[i][j - 1] + M[i + 1][j - 1] + M[i + 1][j] +
                  M[i + 1][j + 1] + M[i][j + 1];
      }
    }
  }
  for (i = 0; i < H; ++i) {
    for (j = 0; j < W; ++j) {
      if (M[i][j] == 0)
        cout << N[i][j];
      else
        cout << '#';
    }
    cout << endl;
  }
  return 0;
}
