#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> board(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> board.at(i).at(j);
    }
  }
  for (int i = 1; i < H - 1; i++) {
    for (int j = 1; j < W - 1; j++) {
      if (board.at(i).at(j) == '.') {
        int count = 0;
        if (board.at(i - 1).at(j + 1) == '#') {
          count++;
        }
        if (board.at(i - 1).at(j) == '#') {
          count++;
        }
        if (board.at(i - 1).at(j - 1) == '#') {
          count++;
        }
        if (board.at(i).at(j + 1) == '#') {
          count++;
        }
        if (board.at(i).at(j - 1) == '#') {
          count++;
        }
        if (board.at(i + 1).at(j + 1) == '#') {
          count++;
        }
        if (board.at(i + 1).at(j) == '#') {
          count++;
        }
        if (board.at(i + 1).at(j - 1) == '#') {
          count++;
        }
        board.at(i).at(j) = '0' + count;
      }
    }
  }
  for (int j = 1; j < W - 1; j++) {
    if (board.at(0).at(j) == '.') {
      int count = 0;
      if (board.at(0).at(j - 1) == '#') {
        count++;
      }
      if (board.at(0).at(j + 1) == '#') {
        count++;
      }
      if (board.at(1).at(j - 1) == '#') {
        count++;
      }
      if (board.at(1).at(j) == '#') {
        count++;
      }
      if (board.at(1).at(j + 1) == '#') {
        count++;
      }
      board.at(0).at(j) = '0' + count;
    }
  }
  for (int j = 1; j < W - 1; j++) {
    if (board.at(H - 1).at(j) == '.') {
      int count = 0;
      if (board.at(H - 1).at(j - 1) == '#') {
        count++;
      }
      if (board.at(H - 1).at(j + 1) == '#') {
        count++;
      }
      if (board.at(H - 2).at(j - 1) == '#') {
        count++;
      }
      if (board.at(H - 2).at(j) == '#') {
        count++;
      }
      if (board.at(H - 2).at(j + 1) == '#') {
        count++;
      }
      board.at(H - 1).at(j) = '0' + count;
    }
  }
  for (int i = 1; i < H - 1; i++) {
    if (board.at(i).at(0) == '.') {
      int count = 0;
      if (board.at(i - 1).at(0) == '#') {
        count++;
      }
      if (board.at(i + 1).at(0) == '#') {
        count++;
      }
      if (board.at(i - 1).at(1) == '#') {
        count++;
      }
      if (board.at(i).at(1) == '#') {
        count++;
      }
      if (board.at(i + 1).at(1) == '#') {
        count++;
      }
      board.at(i).at(0) = '0' + count;
    }
  }
  for (int i = 1; i < H - 1; i++) {
    if (board.at(i).at(W - 1) == '.') {
      int count = 0;
      if (board.at(i - 1).at(W - 1) == '#') {
        count++;
      }
      if (board.at(i + 1).at(W - 1) == '#') {
        count++;
      }
      if (board.at(i - 1).at(W - 2) == '#') {
        count++;
      }
      if (board.at(i).at(W - 2) == '#') {
        count++;
      }
      if (board.at(i + 1).at(W - 2) == '#') {
        count++;
      }
      board.at(i).at(W - 1) = '0' + count;
    }
  }
  if (board.at(0).at(0) == '.') {
    int count = 0;
    if (board.at(0).at(1) == '#') {
      count++;
    }
    if (board.at(1).at(0) == '#') {
      count++;
    }
    if (board.at(1).at(1) == '#') {
      count++;
    }
    board.at(0).at(0) = '0' + count;
  }
  if (board.at(0).at(W - 1) == '.') {
    int count = 0;
    if (board.at(0).at(W - 2) == '#') {
      count++;
    }
    if (board.at(1).at(W - 2) == '#') {
      count++;
    }
    if (board.at(1).at(W - 1) == '#') {
      count++;
    }
    board.at(0).at(W - 1) = '0' + count;
  }
  if (board.at(H - 1).at(0) == '.') {
    int count = 0;
    if (board.at(H - 1).at(1) == '#') {
      count++;
    }
    if (board.at(H - 2).at(0) == '#') {
      count++;
    }
    if (board.at(H - 2).at(1) == '#') {
      count++;
    }
    board.at(H - 1).at(0) = '0' + count;
  }
  if (board.at(H - 1).at(W - 1) == '.') {
    int count = 0;
    if (board.at(H - 1).at(W - 2) == '#') {
      count++;
    }
    if (board.at(H - 2).at(W - 2) == '#') {
      count++;
    }
    if (board.at(H - 2).at(W - 1) == '#') {
      count++;
    }
    board.at(H - 1).at(W - 1) = '0' + count;
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << board.at(i).at(j);
    }
    cout << endl;
  }
  return 0;
}
