#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  string grid[100][100];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      grid[i][j] = s[i].substr(j, 1);
    }
  }
  int count;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      count = 0;
      if (grid[i][j] == ".") {
        if (grid[i - 1][j - 1] == "#") {
          count++;
        }
        if (grid[i - 1][j] == "#") {
          count++;
        }
        if (grid[i - 1][j + 1] == "#") {
          count++;
        }
        if (grid[i][j - 1] == "#") {
          count++;
        }
        if (grid[i][j + 1] == "#") {
          count++;
        }
        if (grid[i + 1][j - 1] == "#") {
          count++;
        }
        if (grid[i + 1][j] == "#") {
          count++;
        }
        if (grid[i + 1][j + 1] == "#") {
          count++;
        }
        cout << count;
      } else {
        cout << grid[i][j];
      }
    }
    cout << endl;
  }
}
