#include <bits/stdc++.h>
struct Cell {
  Cell() : x(0), y(0) {}
  Cell(int xx, int yy) : x(xx), y(yy) {}
  int x;
  int y;
};
template <typename T, int MAXSIZE>
class Queue {
 public:
  Queue() : mHead(0), mTail(0) {}
  void push(T e) { mQUEUE[mTail++] = e; }
  T pop(void) {
    T tmp = mQUEUE[mHead++];
    return tmp;
  }
  int size(void) { return mTail - mHead; }

 private:
  T mQUEUE[MAXSIZE];
  int mHead;
  int mTail;
};
template <typename T, int MAXSIZE>
class Stack {
 public:
  Stack() : mTop(0) {}
  void push(T e) { mSTACK[mTop++] = e; }
  T pop(void) { return mSTACK[--mTop]; }
  int size(void) { return mTop; }

 private:
  T mSTACK[MAXSIZE];
  int mTop;
};
int MAP[1002][1002];
int cohMAP[1002][1002];
bool Visited[1002][1002];
char Ans[1002][1002];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
Stack<Cell, 1000000> cellsStack;
Queue<Cell, 1000000> visitedQueue;
Queue<Cell, 1000000> filledQueue;
Queue<Cell, 1000000> emptyQueue;
void dfs(int x, int y, int run) {
  int depth = 0, nextX, nextY;
  Cell cur;
  cellsStack.push(Cell(x, y));
  while (cellsStack.size() > 0) {
    cur = cellsStack.pop();
    if (!Visited[cur.y][cur.x]) {
      Visited[cur.y][cur.x] = true;
      visitedQueue.push(cur);
      ++depth;
      for (int i = 0; i < 4; ++i) {
        nextX = cur.x + dx[i];
        nextY = cur.y + dy[i];
        if (MAP[nextY][nextX] == 1 && !Visited[nextY][nextX]) {
          cellsStack.push(Cell(nextX, nextY));
        }
      }
    }
  }
  while (visitedQueue.size() > 0) {
    cur = visitedQueue.pop();
    MAP[cur.y][cur.x] = depth;
    cohMAP[cur.y][cur.x] = run;
  }
}
int main() {
  int n, m;
  char buf[1003];
  scanf("%d %d\n", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s\n", &buf[1]);
    for (int j = 1; j <= m; ++j) {
      if (buf[j] == '.') {
        MAP[i][j] = 1;
        Ans[i][j] = '.';
        emptyQueue.push(Cell(j, i));
      } else {
        filledQueue.push(Cell(j, i));
      }
    }
  }
  Cell cur;
  int run = 0;
  while (emptyQueue.size() > 0) {
    cur = emptyQueue.pop();
    if (!Visited[cur.y][cur.x]) {
      dfs(cur.x, cur.y, ++run);
    }
  }
  int ans;
  bool isSame;
  int cohences[4];
  while (filledQueue.size() > 0) {
    ans = 1;
    cur = filledQueue.pop();
    for (int i = 0; i < 4; ++i) {
      cohences[i] = cohMAP[cur.y + dy[i]][cur.x + dx[i]];
      if (cohences[i] > 0) {
        isSame = false;
        for (int j = 0; j < i; ++j) {
          if (cohences[i] == cohences[j]) {
            isSame = true;
            break;
          }
        }
        if (!isSame) {
          ans += MAP[cur.y + dy[i]][cur.x + dx[i]];
        }
      }
    }
    Ans[cur.y][cur.x] = (ans % 10) + '0';
  }
  for (int i = 1; i <= n; ++i) {
    printf("%s\n", &Ans[i][1]);
  }
  return 0;
}
