#include <bits/stdc++.h>
using namespace std;

int main(){
  int H, W, count;
  string s1, s2, s3, f;
  cin >> H >> W;
  cin >> s1 >> s2 >> s3;
  
  for (int i; i<W; i++) {
    f += "f";
  }
  if (H == 1) {
    for (int i=0; i<W; i++) {
      s2 += "f";
    }
  }
  if (H == 2) {
    for (int i=0; i<W; i++) {
      s3 += "f";
    }
  }
  
  for (int i=0; i<H; i++) {  
    if (i == 0) {
      for (int j=0; j<W; j++) {
        count = 0;
        if (j == 0) {
          if (s1.at(j) == '.') {
            if (W != 1) {
              if (s1.at(j+1) == '#')
                count++;
            }
            if (s2 == f) {
              cout << count;
              continue;
            }
            if (s2.at(j) == '#')
              count++;
            if (W != 1) {
              if (s2.at(j+1) == '#')
                count++;
            }
            cout << count;
          }
          else {
            cout << '#';
          }
        }
        else if (j > 0 && j < W-1) {
          if (s1.at(j) == '.') {
            if (s1.at(j-1) == '#')
              count++;
            if (s1.at(j+1) == '#')
              count++;
            if (s2 == f) {
              cout << count;
              continue;
            }
            if (s2.at(j) == '#')
              count++;
            if (s2.at(j-1) == '#')
              count++;
            if (s2.at(j+1) == '#')
              count++;
            cout << count;
          }
          else {
            cout << '#';
          }
        }
        else {
          if (s1.at(j) == '.') {
            if (s1.at(j-1) == '#')
              count++;
            if (s2 == f) {
              cout << count;
              continue;
            }
            if (s2.at(j) == '#')
              count++;
            if (s2.at(j-1) == '#')
              count++;
            cout << count;
          }
          else {
            cout << '#';
          }
        }
      }
    }
    
    else if (i > 0 && i < H-1) {
      for (int j=0; j<W; j++) {
        count = 0;
        if (j == 0) {
          if (s2.at(j) == '.') {
            if (s1.at(j) == '#')
              count++;
            if (W != 1) {
              if (s1.at(j+1) == '#')
              	count++;
              if (s2.at(j+1) == '#')
                count++;
              if (s3.at(j+1) == '#')
                count++;
            }
            if (s3.at(j) == '#')
              count++;
            cout << count;
          }
          else {
            cout << '#';
          }
        }
        else if (j > 0 && j < W-1) {
          if (s2.at(j) == '.') {
            if (s1.at(j) == '#')
              count++;
            if (s1.at(j-1) == '#')
              count++;
            if (s1.at(j+1) == '#')
              count++;
            if (s2.at(j-1) == '#')
              count++;
            if (s2.at(j+1) == '#')
              count++;
            if (s3.at(j) == '#')
              count++;
            if (s3.at(j-1) == '#')
              count++;
            if (s3.at(j+1) == '#')
              count++;
            cout << count;
          }
          else {
            cout << '#';
          }
        }
        else {
          if (s2.at(j) == '.') {
            if (s1.at(j) == '#')
              count++;
            if (s1.at(j-1) == '#')
              count++;
            if (s2.at(j-1) == '#')
              count++;
            if (s3.at(j) == '#')
              count++;
            if (s3.at(j-1) == '#')
              count++;
            cout << count;
          }
          else {
            cout << '#';
          }
        }
      }
      if (i != H-2) {
        s1 = s2;
        s2 = s3;
        cin >> s3;
      }
    }
    
    else {
      if (s3 == f) {
        s3 = s2;
        s2 = s1;
      }
      for (int j=0; j<W; j++) {
        count = 0;
        if (j == 0) {
          if (s3.at(j) == '.') {
            if (s2.at(j) == '#')
              count++;
            if (W != 1) {
              if (s3.at(j+1) == '#')
              	count++;
              if (s2.at(j+1) == '#')
                count++;
            }
            cout << count;
          }
          else {
            cout << '#';
          }
        }
        else if (j > 0 && j < W-1) {
          if (s3.at(j) == '.') {
            if (s3.at(j-1) == '#')
              count++;
            if (s3.at(j+1) == '#')
              count++;
            if (s2.at(j) == '#')
              count++;
            if (s2.at(j-1) == '#')
              count++;
            if (s2.at(j+1) == '#')
              count++;
            cout << count;
          }
          else {
            cout << '#';
          }
        }
        else {
          if (s3.at(j) == '.') {
            if (s3.at(j-1) == '#')
              count++;
            if (s2.at(j) == '#')
              count++;
            if (s2.at(j-1) == '#')
              count++;
            cout << count;
          }
          else {
            cout << '#';
          }
        }
      }
    }
    cout << endl;
    if (s2 == f)
      break;
  }
}

Measured memory_bytes: 256