#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string beforeLine = "", thisLine = "", nextLine = "";
  int bombCounter = 0;
  cin >> beforeLine;
  cin >> thisLine;
  for (int j = 0; j < W; j++) {
    if (beforeLine.at(j) == '#') {
      cout << '#';
      continue;
    } else {
      if (j > 0) {
        if (beforeLine.at(j - 1) == '#') {
          bombCounter++;
        }
      }
      if (j < W - 1) {
        if (beforeLine.at(j + 1) == '#') {
          bombCounter++;
        }
      }
      if (j > 0) {
        if (thisLine.at(j - 1) == '#') {
          bombCounter++;
        }
      }
      if (thisLine.at(j) == '#') {
        bombCounter++;
      }
      if (j < W - 1) {
        if (thisLine.at(j + 1) == '#') {
          bombCounter++;
        }
      }
      cout << bombCounter;
      bombCounter = 0;
    }
  }
  cout << endl;
  for (int i = 0; i < H - 2; i++) {
    cin >> nextLine;
    for (int j = 0; j < W; j++) {
      if (thisLine.at(j) == '#') {
        cout << "#";
        continue;
      } else {
        if (j > 0) {
          if (beforeLine.at(j - 1) == '#') {
            bombCounter++;
          }
        }
        if (beforeLine.at(j) == '#') {
          bombCounter++;
        }
        if (j < W - 1) {
          if (beforeLine.at(j + 1) == '#') {
            bombCounter++;
          }
        }
        if (j > 0) {
          if (thisLine.at(j - 1) == '#') {
            bombCounter++;
          }
        }
        if (j < W - 1) {
          if (thisLine.at(j + 1) == '#') {
            bombCounter++;
          }
        }
        if (j > 0) {
          if (nextLine.at(j - 1) == '#') {
            bombCounter++;
          }
        }
        if (nextLine.at(j) == '#') {
          bombCounter++;
        }
        if (j < W - 1) {
          if (nextLine.at(j + 1) == '#') {
            bombCounter++;
          }
        }
        cout << bombCounter;
        bombCounter = 0;
      }
    }
    cout << endl;
    beforeLine = thisLine;
    thisLine = nextLine;
  }
  for (int j = 0; j < W; j++) {
    if (thisLine.at(j) == '#') {
      cout << '#';
      continue;
    } else {
      if (j > 0) {
        if (beforeLine.at(j - 1) == '#') {
          bombCounter++;
        }
      }
      if (beforeLine.at(j) == '#') {
        bombCounter++;
      }
      if (j < W - 1) {
        if (beforeLine.at(j + 1) == '#') {
          bombCounter++;
        }
      }
      if (j > 0) {
        if (thisLine.at(j - 1) == '#') {
          bombCounter++;
        }
      }
      if (j < W - 1) {
        if (thisLine.at(j + 1) == '#') {
          bombCounter++;
        }
      }
      cout << bombCounter;
      bombCounter = 0;
    }
  }
  cout << endl;
}
