#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;
  
  // first line process
  for (int j=0; j<W; j++) {
    if (beforeLine.at(j) == '#') {
      cout << '#';
      continue;
    } else {
      // before line #firstline, beforeLine means this line
      if (j > 0) {
        if (beforeLine.at(j-1) == '#') {
          bombCounter++;
        }
      }
      if (j < W-1) {
        if (beforeLine.at(j+1) == '#') {
          bombCounter++;
        }
      }

      // this line #firstline, thisLine means nextline
      if (thisLine != "") {
        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;

  if (H > 1) {
    for (int i=0; i<H-2; i++){
      cin >> nextLine;
      for (int j=0; j<W; j++) {
        if (thisLine.at(j) == '#') {
          cout << "#";
          continue;
        } else {
          // before line 
          if (j > 0) {
            if (beforeLine.at(j-1) == '#') {
              bombCounter++;
            }
          }
          if (beforeLine.at(j) == '#') {
            bombCounter++;
          }
          if (j < W-1) {
            if (beforeLine.at(j+1) == '#') {
              bombCounter++;
            }
          }

          // this line
          if (j > 0) {
            if (thisLine.at(j-1) == '#') {
              bombCounter++;
            }
          }
          if (j < W-1) {
            if (thisLine.at(j+1) == '#') {
              bombCounter++;
            }
          }

          // next line
          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 {
        // before line 
        if (j > 0) {
          if (beforeLine.at(j-1) == '#') {
            bombCounter++;
          }
        }
        if (beforeLine.at(j) == '#') {
          bombCounter++;
        }
        if (j < W-1) {
          if (beforeLine.at(j+1) == '#') {
            bombCounter++;
          }
        }

        // this line
        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;
  }
}

Measured memory_bytes: 384