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