#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[50], ss[50];
  int h, w, counter = 0;
  cin >> h >> w;
  if (h >= 1 && h <= 50 && w <= 50 && w >= 1) {
    for (int i = 0; i < h; i++) {
      cin >> s[i];
      if (s[i].size() != w) {
        break;
      }
      for (int j = 0; j < s[i].size(); j++) {
        ss[i][j] = '#';
        if (s[i][j] != '.' && s[i][j] != '#') {
          break;
        }
      }
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] == '.') {
          counter = 0;
          if (i == 0 && j == 0) {
            if (s[i + 1][j] == '#') {
              ++counter;
            }
            if (s[i][j + 1] == '#') {
              ++counter;
            }
            if (s[i + 1][j + 1] == '#') {
              ++counter;
            }
            ss[i][j] = '0' + counter;
          }
          if (i == h - 1 && j == 0) {
            if (s[i - 1][j] == '#') {
              ++counter;
            }
            if (s[i][j + 1] == '#') {
              ++counter;
            }
            if (s[i - 1][j + 1] == '#') {
              ++counter;
            }
            ss[i][j] = '0' + counter;
          }
          if (i == h - 1 && j == s[i].size() - 1) {
            if (s[i - 1][j] == '#') {
              ++counter;
            }
            if (s[i][j - 1] == '#') {
              ++counter;
            }
            if (s[i - 1][j - 1] == '#') {
              ++counter;
            }
            ss[i][j] = '0' + counter;
          }
          if (i == 0 && j == s[i].size() - 1) {
            if (s[i][j - 1] == '#') {
              ++counter;
            }
            if (s[i + 1][j - 1] == '#') {
              ++counter;
            }
            if (s[i + 1][j] == '#') {
              ++counter;
            }
            ss[i][j] = '0' + counter;
          }
          if (i == 0 && j >= i + 1 && j < s[i].size() - 1) {
            for (int k = i; k <= i + 1; k++) {
              for (int l = j - 1; l <= j + 1; l++) {
                if (s[k][l] == '#') {
                  if (!(k == i && l == j)) {
                    ++counter;
                  }
                }
              }
            }
            ss[i][j] = '0' + counter;
          }
          if (i == h - 1 && j > i + 1 && j < s[i].size() - 1) {
            for (int k = i; k <= i - 1; k++) {
              for (int l = j - 1; l <= j + 1; l++) {
                if (!(k == i && l == j)) {
                  if (s[k][l] == '#') {
                    ++counter;
                  }
                }
              }
            }
            ss[i][j] = '0' + counter;
          }
          if (j == 0 && i > j + 1 && i < h - 1) {
            for (int k = j; k <= j + 1; k++) {
              for (int l = i - 1; l <= i + 1; l++) {
                if (!(k == i && l == j)) {
                  if (s[k][l] == '#') {
                    ++counter;
                  }
                }
              }
            }
            ss[i][j] = '0' + counter;
          }
          if (j == s[i].size() - 1 && i > j + 1 && i < h - 1) {
            for (int k = j; k <= j - 1; k++) {
              for (int l = i - 1; l <= i + 1; l++) {
                if (!(k == i && l == j)) {
                  if (s[k][l] == '#') {
                    ++counter;
                  }
                }
              }
            }
            ss[i][j] = '0' + counter;
          }
          if (i >= 1 && i <= h - 1) {
            if (j >= 1 && j < s[i].size() - 1) {
              for (int k = i - 1; k <= i + 1; k++) {
                for (int l = j - 1; l <= j + 1; l++) {
                  if (!(k == i && l == j)) {
                    if (s[k][l] == '#') {
                      ++counter;
                    }
                  }
                }
              }
              ss[i][j] = '0' + counter;
            }
          }
        }
      }
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < s[i].size(); j++) cout << ss[i][j];
      cout << endl;
    }
  }
  return 0;
}
