#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (int i = 0; i < H; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '#') {
        continue;
      }
      s[i][j] = '0';
      if (i != 0) {
        if (s[i - 1][j] == '#') {
          s[i][j] = s[i][j] - '0' + '1';
        }
        if (j != 0) {
          if (s[i - 1][j - 1] == '#') {
            s[i][j] = s[i][j] - '0' + '1';
          }
        }
      }
      if (i != W - 1) {
        if (s[i + 1][j] == '#') {
          s[i][j] = s[i][j] - '0' + '1';
        }
        if (j != W - 1) {
          if (s[i - 1][j + 1] == '#') {
            s[i][j] = s[i][j] - '0' + '1';
          }
        }
      }
      if (j != 0) {
        if (s[i][j - 1] == '#') {
          s[i][j] = s[i][j] - '0' + '1';
        }
        if (i != W - 1) {
          if (s[i + 1][j - 1] == '#') {
            s[i][j] = s[i][j] - '0' + '1';
          }
        }
      }
      if (j != W - 1) {
        if (s[i][j + 1] == '#') {
          s[i][j] = s[i][j] - '0' + '1';
        }
        if (i != 0) {
          if (s[i - 1][j + 1] == '#') {
            s[i][j] = s[i][j] - '0' + '1';
          }
        }
      }
    }
  }
  for (int i = 0; i < H; i++) {
    cout << s[i] << endl;
  }
}
