#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 (h == 1 && w == 1) {
    if (grid.at(0).at(0) == '#') cout << grid.at(0).at(0) << endl;
    else cout << 0 << endl;
    return 0;
  }

  if (h == 1) {
    if (grid.at(0).at(0) == '.') {
      if (grid.at(0).at(1) == '#') bomb.at(0).at(0) = '1';
      else bomb.at(0).at(0) = '0';
    }
    if (grid.at(0).at(w - 1) == '.') {
      if (grid.at(0).at(w - 2) == '#') bomb.at(0).at(w - 1) = '1';
      else bomb.at(0).at(w - 1) = '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++;
      bomb.at(0).at(i) = 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;
    }
    return 0;
  }

  if (w == 1) {
    if (grid.at(0).at(0) == '.') {
      if (grid.at(1).at(0) == '#') bomb.at(0).at(0) = '1';
      else bomb.at(0).at(0) = '0';
    }
    if (grid.at(h - 1).at(0) == '.') {
      if (grid.at(h - 2).at(0) == '#') bomb.at(h - 1).at(0) = '1';
      else bomb.at(h - 1).at(0) = '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++;
      bomb.at(i).at(0) = 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;
    }
    return 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;
  }
}

Measured memory_bytes: 256