#include <bits/stdc++.h>
using namespace std;
char itoa(int i) {
  switch (i) {
    case 0:
      return '0';
    case 1:
      return '1';
    case 2:
      return '2';
    case 3:
      return '3';
    case 4:
      return '4';
    case 5:
      return '5';
    case 6:
      return '6';
    case 7:
      return '7';
    case 8:
      return '8';
    case 9:
      return '9';
    default:
      return '0';
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int H, W, cnt = 0, cntB;
  string S[50];
  int Bh[50], Bw[50];
  cin >> H >> W;
  for (long long i = 0; i < (long long)(H); i++) {
    cin >> S[i];
  }
  for (long long i = 0; i < (long long)(H); i++) {
    for (long long j = 0; j < (long long)(W); j++) {
      if (S[i][j] == '#') {
        Bh[cnt] = i;
        Bw[cnt] = j;
        cnt++;
      }
    }
  }
  for (long long i = 0; i < (long long)(H); i++) {
    for (long long j = 0; j < (long long)(W); j++) {
      if (S[i][j] == '.') {
        cntB = 0;
        for (long long a = 0; a < (long long)(cnt); a++) {
          if ((Bh[a] == i + 1 && Bw[a] == j - 1) ||
              (Bh[a] == i + 1 && Bw[a] == j) ||
              (Bh[a] == i + 1 && Bw[a] == j + 1) ||
              (Bh[a] == i && Bw[a] == j - 1) ||
              (Bh[a] == i && Bw[a] == j + 1) ||
              (Bh[a] == i - 1 && Bw[a] == j - 1) ||
              (Bh[a] == i - 1 && Bw[a] == j) ||
              (Bh[a] == i - 1 && Bw[a] == j + 1)) {
            cntB++;
          }
        }
        S[i][j] = itoa(cntB);
      }
    }
  }
  for (long long i = 0; i < (long long)(H); i++) {
    cout << S[i];
    cout << endl;
  }
  return 0;
}
