#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  int c[h][w];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> s[i][j];
      c[i][j] = 0;
    }
  }
  int deltaArrayM[8] = {1, 0, -1, 0, 1, -1, 1, -1};
  int deltaArrayN[8] = {0, 1, 0, -1, 1, -1, -1, 1};
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') {
        for (int k = 0; k < 8; ++k) {
          int deltaM = i + deltaArrayM[k];
          int deltaN = j + deltaArrayN[k];
          if ((deltaM < 0) || (deltaM > h) || (deltaN < 0) || (deltaN > w)) {
            continue;
          }
          if (s[deltaM][deltaN] != '#') {
            c[deltaM][deltaN] += 1;
          }
        }
      }
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#')
        cout << '#';
      else
        cout << c[i][j];
    }
    cout << "\n";
  }
}
