#include <bits/stdc++.h>
using namespace std;
template <typename T>
void remove(vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}
vector<string> split(const string &s, char c);
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void) {
  int w, h;
  cin >> h >> w;
  char state[h][w];
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      cin >> state[i][j];
    }
  for (int y = 0; y < (int)(h); y++) {
    for (int x = 0; x < (int)(w); x++) {
      cout << state[y][x];
    }
    cout << endl;
  }
  int ans[h][w];
  fill_n(*ans, w * h, 0);
  for (int y = 0; y < (int)(h); y++)
    for (int x = 0; x < (int)(w); x++) {
      if (state[y][x] != '#') continue;
      for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
          int nowx = x + j;
          int nowy = y + i;
          if (nowx == -1 || nowx == w || nowy == -1 || nowy == h) continue;
          ans[nowy][nowx]++;
        }
      }
    }
  for (int y = 0; y < (int)(h); y++) {
    for (int x = 0; x < (int)(w); x++) {
      if (state[y][x] == '#')
        cout << '#';
      else
        cout << ans[y][x];
    }
    cout << endl;
  }
  return 0;
}
int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}
vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (int i = 0; i < s.size(); i++) {
    char ch = s[i];
    if (ch == delim) {
      if (!item.empty()) elems.push_back(item);
      item.clear();
    } else {
      item += ch;
    }
  }
  if (!item.empty()) elems.push_back(item);
  return elems;
}
