#include <bits/stdc++.h>
using namespace std;
int main() {
  int R = 0, H, W;
  string New, Now, Old;
  cin >> H >> W >> New;
  Old = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  for (int i = 0; i < H; i++) {
    Now = New;
    New = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    if (i != H - 1) cin >> New;
    for (int j = 0; j < W; j++) {
      if (Now.at(j) == '.') {
        if (j > 0) {
          if (Old.at(j - 1) == '#') R++;
          if (Now.at(j - 1) == '#') R++;
          if (New.at(j - 1) == '#') R++;
        }
        if (j < W - 1) {
          if (Old.at(j + 1) == '#') R++;
          if (Now.at(j + 1) == '#') R++;
          if (New.at(j + 1) == '#') R++;
        }
        if (Old.at(j) == '#') R++;
        if (New.at(j) == '#') R++;
        Now.at(j) = R;
        R = 0;
      }
    }
    cout << Now << endl;
    Old = Now;
  }
}
