#include <iostream>
#include <cstring>
using namespace std;
int n, m;
int bomb[105][105];
char ch;
int isbomb(char c) {
return c == '*' ? -1 : 0;
}
int countbomb(int x, int y) {
return bomb[x][y] == -1 ? 1 : 0;
}
void check_and_solve(int x, int y) {
if (x)bomb[x][y] += countbomb(x - 1, y);
if (y)bomb[x][y] += countbomb(x, y - 1);
if ((n - x - 1))bomb[x][y] += countbomb(x + 1, y);
if ((m - y - 1))bomb[x][y] += countbomb(x, y + 1);
if (x && y)
bomb[x][y] += countbomb(x - 1, y - 1);
if (x && !(m - y - 1))
bomb[x][y] += countbomb(x - 1, y + 1);
if ((n - x - 1) && y)
bomb[x][y] += countbomb(x + 1, y - 1);
if ((n - x - 1) && (m - y - 1))
bomb[x][y] += countbomb(x + 1, y + 1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> ch;
bomb[i][j] = isbomb(ch);
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (!bomb[i][j]) {
check_and_solve(i, j);
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (!(bomb[i][j] + 1)) {
cout << '*';
continue;
}
cout << bomb[i][j];
}
cout << endl;
}
}