#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  int i, j, k, l;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  cout << 1;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (s[i][j] != '#') {
        int count = 0;
        for (k = max(i - 1, 0); k < i + 2; k++) {
          for (l = max(j - 1, 0); l < j + 2; l++) {
            if (s[k][l] == '#') {
              count++;
            }
          }
        }
        cout << s[i][j];
        s[i][j] = (char)count;
        cout << (int)s[i][j];
      }
    }
  }
  cout << endl << endl;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (s[i][j] != '#') {
        cout << (int)s[i][j];
      } else {
        cout << s[i][j];
      }
    }
    cout << endl;
  }
  return 0;
}
