#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, count = 0;
  cin >> h >> w;
  string s[50];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 1; i < h - 1; i++) {
    for (int j = 1; j < w - 1; j++) {
      if (s[i][j] == '.') {
        for (int k = i - 1; k < i + 2; k++) {
          for (int l = j - 1; l < j + 2; l++) {
            if (s[k][l] == '#') count++;
          }
        }
        s[i][j] = '0' + count;
        count = 0;
      }
    }
  }
  for (int i = 1; i < h - 1; i++) {
    if (s[i][0] == '.') {
      for (int k = i - 1; k < i + 2; k++) {
        if (s[k][0] == '#') count++;
        if (s[k][1] == '#') count++;
      }
      s[i][0] = '0' + count;
      count = 0;
    }
    if (s[i][w - 1] == '.') {
      for (int k = i - 1; k < i + 2; k++) {
        if (s[k][w - 1] == '#') count++;
        if (s[k][w - 2] == '#') count++;
      }
      s[i][w - 1] = '0' + count;
      count = 0;
    }
  }
  for (int i = 1; i < w - 1; i++) {
    if (s[0][i] == '.') {
      for (int k = i - 1; k < i + 2; k++) {
        if (s[0][k] == '#') count++;
        if (s[1][k] == '#') count++;
      }
      s[0][i] = '0' + count;
      count = 0;
    }
    if (s[h - 1][i] == '.') {
      for (int k = i - 1; k < i + 2; k++) {
        if (s[h - 1][k] == '#') count++;
        if (s[h - 2][k] == '#') count++;
      }
      s[h - 1][i] = '0' + count;
      count = 0;
    }
  }
  if (s[0][0] == '.') {
    if (s[0][1] == '#') count++;
    if (s[1][0] == '#') count++;
    if (s[1][1] == '#') count++;
    s[0][0] = '0' + count;
    count = 0;
  }
  if (s[h - 1][w - 1] == '.') {
    if (s[h - 2][w - 2] == '#') count++;
    s[h - 1][w - 1] = '0' + count;
    count = 0;
  }
  if (s[h - 1][0] == '.') {
    if (s[h - 1][1] == '#') count++;
    if (s[h - 2][0] == '#') count++;
    if (s[h - 2][1] == '#') count++;
    s[h - 1][0] = '0' + count;
    count = 0;
  }
  if (s[0][w - 1] == '.') {
    if (s[0][w - 2] == '#') count++;
    if (s[1][w - 1] == '#') count++;
    if (s[1][w - 2] == '#') count++;
    s[0][w - 1] = '0' + count;
    count = 0;
  }
  for (int i = 0; i < h; i++) {
    cout << s[i] << endl;
  }
  return 0;
}
