#include <bits/stdc++.h>
using namespace std;
long long h, w;
vector<vector<long long> > ansMap;
void check(vector<vector<bool> > isBomMap, long long tate, long long yoko) {
  if (tate > 0 && yoko > 0 && isBomMap[tate - 1][yoko - 1])
    ansMap[tate][yoko]++;
  if (tate > 0)
    if (isBomMap[tate - 1][yoko]) ansMap[tate][yoko]++;
  if (tate > 0 && yoko < w - 1)
    if (isBomMap[tate - 1][yoko + 1]) ansMap[tate][yoko]++;
  if (yoko < w - 1)
    if (isBomMap[tate][yoko + 1]) ansMap[tate][yoko]++;
  if (tate < h - 1 && yoko < w - 1)
    if (isBomMap[tate + 1][yoko + 1]) ansMap[tate][yoko]++;
  if (tate < h - 1)
    if (isBomMap[tate + 1][yoko]) ansMap[tate][yoko]++;
  if (tate < h - 1 && yoko > 0)
    if (isBomMap[tate + 1][yoko - 1]) ansMap[tate][yoko]++;
  if (yoko > 0)
    if (isBomMap[tate][yoko - 1]) ansMap[tate][yoko]++;
}
int main() {
  cin >> h >> w;
  vector<vector<bool> > isBomMap(h, vector<bool>(w, false));
  ansMap.resize(h, vector<long long>(w, 0));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      isBomMap[i][j] = (c == '.' ? false : true);
    }
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (!isBomMap[i][j]) check(isBomMap, i, j);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!ansMap[i][j])
        cout << "#";
      else
        cout << ansMap[i][j];
    }
    cout << endl;
  }
  return 0;
}
