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