#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) cin >> grid.at(i);
  vector<vector<char> > bomb(h, vector<char>(w, '#'));
  int cnt = 0;
  if (grid.at(0).at(0) == '.') {
    if (grid.at(0).at(1) == '#') cnt++;
    if (grid.at(1).at(0) == '#') cnt++;
    if (grid.at(1).at(1) == '#') cnt++;
    bomb.at(0).at(0) = cnt + '0';
    cnt = 0;
  }
  if (grid.at(0).at(w - 1) == '.') {
    if (grid.at(0).at(w - 2) == '#') cnt++;
    if (grid.at(1).at(w - 1) == '#') cnt++;
    if (grid.at(1).at(w - 2) == '#') cnt++;
    bomb.at(0).at(w - 1) = cnt + '0';
    cnt = 0;
  }
  if (grid.at(h - 1).at(0) == '.') {
    if (grid.at(h - 2).at(0) == '#') cnt++;
    if (grid.at(h - 1).at(1) == '#') cnt++;
    if (grid.at(h - 2).at(1) == '#') cnt++;
    bomb.at(h - 1).at(0) = cnt + '0';
    cnt = 0;
  }
  if (grid.at(h - 1).at(w - 1) == '.') {
    if (grid.at(h - 2).at(w - 1) == '#') cnt++;
    if (grid.at(h - 1).at(w - 2) == '#') cnt++;
    if (grid.at(h - 2).at(w - 2) == '#') cnt++;
    bomb.at(h - 1).at(w - 1) = cnt + '0';
    cnt = 0;
  }
  for (int i = 1; i <= w - 2; i++) {
    if (grid.at(0).at(i) == '#') continue;
    if (grid.at(0).at(i - 1) == '#') cnt++;
    if (grid.at(0).at(i + 1) == '#') cnt++;
    if (grid.at(1).at(i - 1) == '#') cnt++;
    if (grid.at(1).at(i) == '#') cnt++;
    if (grid.at(1).at(i + 1) == '#') cnt++;
    bomb.at(0).at(i) = cnt + '0';
    cnt = 0;
  }
  for (int i = 1; i <= w - 2; i++) {
    if (grid.at(h - 1).at(i) == '#') continue;
    if (grid.at(h - 1).at(i - 1) == '#') cnt++;
    if (grid.at(h - 1).at(i + 1) == '#') cnt++;
    if (grid.at(h - 2).at(i - 1) == '#') cnt++;
    if (grid.at(h - 2).at(i) == '#') cnt++;
    if (grid.at(h - 2).at(i + 1) == '#') cnt++;
    bomb.at(h - 1).at(i) = cnt + '0';
    cnt = 0;
  }
  for (int i = 1; i <= h - 2; i++) {
    if (grid.at(i).at(0) == '#') continue;
    if (grid.at(i - 1).at(0) == '#') cnt++;
    if (grid.at(i + 1).at(0) == '#') cnt++;
    if (grid.at(i - 1).at(1) == '#') cnt++;
    if (grid.at(i).at(1) == '#') cnt++;
    if (grid.at(i + 1).at(1) == '#') cnt++;
    bomb.at(i).at(0) = cnt + '0';
    cnt = 0;
  }
  for (int i = 1; i <= h - 2; i++) {
    if (grid.at(i).at(w - 1) == '#') continue;
    if (grid.at(i - 1).at(w - 1) == '#') cnt++;
    if (grid.at(i + 1).at(w - 1) == '#') cnt++;
    if (grid.at(i - 1).at(w - 2) == '#') cnt++;
    if (grid.at(i).at(w - 2) == '#') cnt++;
    if (grid.at(i + 1).at(w - 2) == '#') cnt++;
    bomb.at(i).at(w - 1) = cnt + '0';
    cnt = 0;
  }
  for (int i = 1; i <= h - 2; i++) {
    for (int j = 1; j <= w - 2; j++) {
      if (grid.at(i).at(j) == '#') continue;
      for (int k = i - 1; k <= i + 1; k++) {
        for (int l = j - 1; l <= j + 1; l++) {
          if (k == i && l == j) continue;
          if (grid.at(k).at(l) == '#') cnt++;
        }
      }
      bomb.at(i).at(j) = cnt + '0';
      cnt = 0;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cout << bomb.at(i).at(j);
    cout << endl;
  }
}
