#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  int c;
  int H, W;
  cin >> H >> W;
  char S[51][51];
  char C[51][51];
  if (H == 1 && W == 1) {
    if (S[0][0] == '.') {
      cout << "." << endl;
    } else {
      cout << "#" << endl;
    }
    return 0;
  }
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      c = 0;
      if (S[i][j] == '#') {
        C[i][j] = '#';
        continue;
      } else {
        if (i == 0) {
          if (j == 0) {
            for (int k = 0; k < 2; k++) {
              for (int l = 0; l < 2; l++) {
                if (S[i + k][j + l] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          } else if (j == W - 1) {
            for (int k = 0; k < 2; k++) {
              for (int l = 0; l < 2; l++) {
                if (S[i + k][j + l - 1] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          } else {
            for (int k = 0; k < 2; k++) {
              for (int l = 0; l < 3; l++) {
                if (S[i + k][j + l - 1] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          }
        } else if (i == H - 1) {
          if (j == 0) {
            for (int k = 0; k < 2; k++) {
              for (int l = 0; l < 2; l++) {
                if (S[i + k - 1][j + l] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          } else if (j == W - 1) {
            for (int k = 0; k < 2; k++) {
              for (int l = 0; l < 2; l++) {
                if (S[i + k - 1][j + l - 1] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          } else {
            for (int k = 0; k < 2; k++) {
              for (int l = 0; l < 3; l++) {
                if (S[i + k - 1][j + l - 1] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          }
        } else {
          if (j == 0) {
            for (int k = 0; k < 3; k++) {
              for (int l = 0; l < 2; l++) {
                if (S[i + k - 1][j + l] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          } else if (j == W - 1) {
            for (int k = 0; k < 3; k++) {
              for (int l = 0; l < 2; l++) {
                if (S[i + k - 1][j + l - 1] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          } else {
            for (int k = 0; k < 3; k++) {
              for (int l = 0; l < 3; l++) {
                if (S[i + k - 1][j + l - 1] == '#') c++;
              }
            }
            C[i][j] = '0' + c;
          }
        }
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << C[i][j];
    }
    cout << endl;
  }
  return 0;
}
