#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  char s[55][55], m[55][55];
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) m[i][j] = '0';
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        m[i][j] = '#';
      else {
        if (s[i - 1][j - 1] == '#') m[i][j]++;
        if (s[i - 1][j] == '#') m[i][j]++;
        if (s[i - 1][j + 1] == '#') m[i][j]++;
        if (s[i][j - 1] == '#') m[i][j]++;
        if (s[i][j + 1] == '#') m[i][j]++;
        if (s[i + 1][j - 1] == '#') m[i][j]++;
        if (s[i + 1][j] == '#') m[i][j]++;
        if (s[i + 1][j + 1] == '#') m[i][j]++;
      }
      cout << m[i][j];
    }
    cout << endl;
  }
  return 0;
}
