#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string s[50];
  int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  string c[50][50];
  for (int i = 0; i < H; i++) {
    cin >> s[i];
    for (int j = 0; j < W; j++) {
      c[i][j] = s[i].at(j);
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (c[i][j] == "#") {
        cout << c[i][j];
      } else {
        int num = 0;
        for (int k = 0; k < 8; k++) {
          if (i == 0) {
            if (k == 0 || k == 1 || k == 2) {
              continue;
            }
          }
          if (i == H - 1) {
            if (k == 5 || k == 6 || k == 7) {
              continue;
            }
          }
          if (j == 0) {
            if (k == 0 || k == 3 || k == 5) {
              continue;
            }
          }
          if (j == H - 1) {
            if (k == 2 || k == 4 || k == 7) {
              continue;
            }
          }
          if (c[i + dx[k]][j + dy[k]] == "#") {
            num++;
          }
        }
        cout << num;
      }
    }
    cout << "" << endl;
  }
}
