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