import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int [][] DXDY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

  class Deque {
    int head = 0, tail = 0;
    int [] queue = null;

    public Deque(int size) {
      queue = new int [size];
    }

    public void add(int e) {
      queue[tail++] = e;
    }

    public int poll() {
      return queue[head++];
    }

    public int get(int idx) {
      return queue[idx];
    }

    public void clear() {
      head = tail = 0;
    }

    public int size() {
      return (tail - head);
    }

    public int elements() {
      return tail;
    }

    @Override
    public String toString() {
      return ("[h=" + head + ", t=" + tail + " : " + Arrays.toString(queue) + "]");
    }
  }

//10 10   *.*...*.** ..*...*.** .**.***... ....*.*.** ***....*** .*..*...*. .***.*..*. .*****.*.* *.***.*... ..*..*....
  public void run() throws Exception {
    int n = nextInt();
    int m = nextInt();

    int [][] l = new int [n][m];
    for (int i = 0; i < n; i++) {
      String s = next();
      for (int j = 0; j < m; j++) {
        l[i][j] = (s.charAt(j) == '.') ? 0 : -1;
      }
    }

    Deque xx = new Deque(n * m);
    Deque yy = new Deque(n * m);

    for (int y = 0, k = 10; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] == 0) {
          xx.clear();
          yy.clear();
          xx.add(x);
          yy.add(y);
          l[y][x] = 1;

          while (xx.size() > 0) {
            int cx = xx.poll();
            int cy = yy.poll();

            for (int [] dxdy : DXDY) {
              int nx = cx + dxdy[0];
              int ny = cy + dxdy[1];

              if ((nx >= 0) && (nx < m) && (ny >= 0) && (ny < n) && (l[ny][nx] == 0)) {
                xx.add(nx);
                yy.add(ny);
                l[ny][nx] = 1;
              }
            }
          }

          int kk = xx.elements() % 10;
          for (int i = 0; i < xx.elements(); i++) {
            l[yy.get(i)][xx.get(i)] = kk + k;
          }

          k += 10;
        }
      }
    }

    StringBuffer ans = new StringBuffer();
    BitSet lu = new BitSet();

    for (int y = 0; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] < 0) {
          int k = 1;
          lu.clear();

          for (int [] dxdy : DXDY) {
            int nx = x + dxdy[0];
            int ny = y + dxdy[1];

            if ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n) && (l[ny][nx] > 0)) {
              int kk = l[ny][nx];

              if (!lu.get(kk / 10)) {
                lu.set(kk / 10);
                k += kk % 10;
              }
            }
          }

          ans.append(k % 10);
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P616C().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int [][] DXDY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  final static int SHIFT = 10;
  final static int MASK = (1 << SHIFT) - 1;

  int n, m;
  int [][] l = null;
  ArrayDeque<Integer> f = null;

  void fill(int xy) {
    l[xy & MASK][xy >> SHIFT] = 1;
    f.addLast(xy);

    for (int [] dxdy : DXDY) {
      int nx = (xy >> SHIFT) + dxdy[0];
      int ny = (xy & MASK) + dxdy[1];

      if ((nx >= 0) && (nx < m) && (ny >= 0) && (ny < n) && (l[ny][nx] == 0)) {
        fill((nx << SHIFT) | ny);
      }
    }
  }

  public void run() throws Exception {
    n = nextInt();
    m = nextInt();

    l = new int [n][m];
    for (int i = 0; i < n; i++) {
      String s = next();
      for (int j = 0; j < m; j++) {
        l[i][j] = (s.charAt(j) == '.') ? 0 : -1;
      }
    }

    StringBuffer ans = new StringBuffer();

    for (int y = 0, k = 10; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] == 0) {
          f = new ArrayDeque();
          fill((x << SHIFT) | y);
          int kk = f.size() % 10;

          while (f.size() > 0) {
            int xy = f.pollFirst();
            l[xy & MASK][xy >>> SHIFT] = k + kk;
          }

          k += 10;
        }
      }
    }

    for (int y = 0; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] < 0) {
          int k = 1;
          BitSet lu = new BitSet();

          for (int [] dxdy : DXDY) {
            int nx = x + dxdy[0];
            int ny = y + dxdy[1];

            if ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n) && (l[ny][nx] > 0)) {
              int kk = l[ny][nx];

              if (!lu.get(kk / 10)) {
                lu.set(kk / 10);
                k += kk;
              }
            }
          }

          ans.append(k % 10);
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

  public static void main(String... args) throws Exception {
    new Thread(null, new Runnable() {
      public void run() {
        try {
          br = new BufferedReader(new InputStreamReader(System.in));
          pw = new PrintWriter(new BufferedOutputStream(System.out));
          new P616C().run();
          br.close();
          pw.close();
        } catch (Exception e) { System.err.println(e); }
      }
    }, "1", (1 << 26) + (1 << 25)).start();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int SHIFT = 10;
  final static int MASK = (1 << SHIFT) - 1;
  final static int [][] DXDY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

  class Deque {
    int head = 0, tail = 0;
    int [] queue = null;

    public Deque(int size) {
      queue = new int [size];
    }

    public void add(int e) {
      queue[tail++] = e;
    }

    public int poll() {
      return queue[head++];
    }

    public int get(int idx) {
      return queue[idx];
    }

    public void clear() {
      head = tail = 0;
    }

    public int size() {
      return (tail - head);
    }

    public int elements() {
      return tail;
    }

    @Override
    public String toString() {
      return ("[h=" + head + ", t=" + tail + " : " + Arrays.toString(queue) + "]");
    }
  }

//10 10   *.*...*.** ..*...*.** .**.***... ....*.*.** ***....*** .*..*...*. .***.*..*. .*****.*.* *.***.*... ..*..*....
  public void run() throws Exception {
    int n = nextInt();
    int m = nextInt();

    int [][] l = new int [n][m];
    for (int i = 0; i < n; i++) {
      String s = next();
      for (int j = 0; j < m; j++) {
        l[i][j] = (s.charAt(j) == '.') ? 0 : -1;
      }
    }

    Deque xy = new Deque(n * m + 1);

    for (int y = 0, k = 10; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] == 0) {
          xy.clear();
          xy.add((x << SHIFT) | y);
          l[y][x] = 1;

          while (xy.size() > 0) {
            int cxy = xy.poll();

            for (int [] dxdy : DXDY) {
              int nx = (cxy >> SHIFT) + dxdy[0];
              int ny = (cxy & MASK) + dxdy[1];

              if ((nx >= 0) && (nx < m) && (ny >= 0) && (ny < n) && (l[ny][nx] == 0)) {
                xy.add((nx << SHIFT) | ny);
                l[ny][nx] = 1;
              }
            }
          }

          int kk = xy.elements() % 10;
          for (int i = xy.elements() - 1; i >= 0; i--) {
            int cxy = xy.get(i);
            l[cxy & MASK][cxy >> SHIFT] = kk + k;
          }

          k += 10;
        }
      }
    }

    StringBuffer ans = new StringBuffer();
    BitSet lu = new BitSet(1000 * 1000 / 2 + 1);

    for (int y = 0; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] < 0) {
          int k = 1;
          lu.clear();

          for (int [] dxdy : DXDY) {
            int nx = x + dxdy[0];
            int ny = y + dxdy[1];

            if ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n) && (l[ny][nx] > 0)) {
              int kk = l[ny][nx];

              if (!lu.get(kk / 10)) {
                lu.set(kk / 10);
                k += kk % 10;
              }
            }
          }

          ans.append(k % 10);
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P616C().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int SHIFT = 10;
  final static int MASK = (1 << SHIFT) - 1;
  final static int [][] DXDY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

  class Deque {
    int head = 0, tail = 0;
    int [] queue = null;

    public Deque(int size) {
      queue = new int [size];
    }

    public void add(int e) {
      queue[tail++] = e;
    }

    public int poll() {
      return queue[head++];
    }

    public int get(int idx) {
      return queue[idx];
    }

    public void clear() {
      head = tail = 0;
    }

    public int size() {
      return (tail - head);
    }

    public int elements() {
      return tail;
    }

    @Override
    public String toString() {
      return ("[h=" + head + ", t=" + tail + " : " + Arrays.toString(queue) + "]");
    }
  }

//10 10   *.*...*.** ..*...*.** .**.***... ....*.*.** ***....*** .*..*...*. .***.*..*. .*****.*.* *.***.*... ..*..*....
  public void run() throws Exception {
    int n = nextInt();
    int m = nextInt();

    int [][] l = new int [n][m];
    for (int i = 0; i < n; i++) {
      String s = next();
      for (int j = 0; j < m; j++) {
        l[i][j] = (s.charAt(j) == '.') ? 0 : -1;
      }
    }

    int [] queue = new int [n * m + 1];
//    Deque xy = new Deque(n * m + 1);

    for (int y = 0, k = 10; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] == 0) {
          int head = 0, tail = 0;
//          xy.clear();
          queue[tail++] = (x << SHIFT) | y;
//          xy.add((x << SHIFT) | y);
          l[y][x] = 1;

//          while (xy.size() > 0) {
          while (head != tail) {
            int cxy = queue[head++];
//            int cxy = xy.poll();

            for (int [] dxdy : DXDY) {
              int nx = (cxy >> SHIFT) + dxdy[0];
              int ny = (cxy & MASK) + dxdy[1];

              if ((nx >= 0) && (nx < m) && (ny >= 0) && (ny < n) && (l[ny][nx] == 0)) {
                queue[tail++] = (nx << SHIFT) | ny;
//                xy.add((nx << SHIFT) | ny);
                l[ny][nx] = 1;
              }
            }
          }

          int kk = tail % 10;
//          int kk = xy.elements() % 10;
          for (int i = tail - 1; i >= 0; i--) {
//          for (int i = xy.elements() - 1; i >= 0; i--) {
            int cxy = queue[i];
//            int cxy = xy.get(i);
            l[cxy & MASK][cxy >> SHIFT] = kk + k;
          }

          k += 10;
        }
      }
    }

    StringBuffer ans = new StringBuffer(n * (m + 3));
    BitSet lu = new BitSet(1000 * 1000 / 2 + 1);

    for (int y = 0; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] < 0) {
          int k = 1;
          lu.clear();

          for (int [] dxdy : DXDY) {
            int nx = x + dxdy[0];
            int ny = y + dxdy[1];

            if ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n) && (l[ny][nx] > 0)) {
              int kk = l[ny][nx];

              if (!lu.get(kk / 10)) {
                lu.set(kk / 10);
                k += kk % 10;
              }
            }
          }

          ans.append(k % 10);
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P616C().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int X = 0, Y = 1;
  final static int [][] DXY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  final static int SHIFT = 32;
  final static long MASK = (1L << SHIFT) - 1;

  int h, w;
  long [][] f;

  void fill(int x, int y, long l) {
    Deque<Long> cxy = new ArrayDeque();
    List<Long> rxy = new ArrayList();
    long xy = ((long)x << SHIFT) | (long)y;
    cxy.add(xy); rxy.add(xy); f[y][x] = l << SHIFT;
    int k = 1;

    while (cxy.size() > 0) {
      xy = cxy.pollFirst();
      x = (int)(xy >>> SHIFT);
      y = (int)(xy & MASK);

      for (int [] dxy : DXY) {
        int nx = x + dxy[X], ny = y + dxy[Y];

        if (f[ny][nx] == 0) {
          xy = ((long)nx << SHIFT) | (long)ny;
          cxy.add(xy); rxy.add(xy); f[ny][nx] = l << SHIFT;
          k++;
        }
      }
    }

    for (Long uxy : rxy) {
      f[(int)(uxy & MASK)][(int)(uxy >>> SHIFT)] |= k;
    }
  }

  public void run() throws Exception {
    h = nextInt();
    w = nextInt();
    f = new long [h + 2][w + 2];
    Arrays.fill(f[0], -1);
    f[h + 1] = f[0];
    for (int y = 1; y <= h; y++) {
      String s = next();
      for (int x = 0; x <= (w + 1); x++) {
        if ((x == 0) || (x == (w + 1))) {
          f[y][x] = -1;
        } else if (s.charAt(x - 1) == '*') {
          f[y][x] = -1;
        }
      }
    }

    for (int y = 1, l = 1; y <= h; y++) {
      for (int x = 1; x <= w; x++) {
        if (f[y][x] == 0) {
          fill(x, y, l);
          l++;
        }
      }
    }
//Arrays.stream(f).forEach(x -> { Arrays.stream(x).forEach(y -> print("[" + (int)(y >>> SHIFT) + ", " + (int)(y & MASK) + "]")); println(); });

    for (int y = 1; y <= h; y++) {
      StringBuilder ans = new StringBuilder(w);
      for (int x = 1; x <= w; x++) {
        if (f[y][x] != -1) {
          ans.append('.');
        } else {
          int k = 1;
          List<Integer> wl = new ArrayList();

lab:      for (int [] dxy : DXY) {
            int xx = x + dxy[X], yy = y + dxy[Y];
            if (f[yy][xx] != -1) {
              int l = (int)(f[yy][xx] >>> SHIFT);
              for (int cl : wl) {
                if (cl == l) {
                  continue lab;
                }
              }
              wl.add(l);
              k += (int)(f[yy][xx] & MASK);
            }
          }

          ans.append(k % 10);
        }
      }
      println(ans);
    }
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P616C().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    return ((b > 0) ? gcd(b, a % b) : a);
  }
  long gcd(long a, long b) {
    return ((b > 0) ? gcd(b, a % b) : a);
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int [][] DXDY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  final static int SHIFT = 10;
  final static int MASK = (1 << SHIFT) - 1;

  int n, m;
  int [][] l = null;
  ArrayDeque<Integer> f = null;

  void fill(int xy) {
    l[xy & MASK][xy >> SHIFT] = 1;
    f.add(xy);

    for (int [] dxdy : DXDY) {
      int nx = (xy >> SHIFT) + dxdy[0];
      int ny = (xy & MASK) + dxdy[1];

      if ((nx >= 0) && (nx < m) && (ny >= 0) && (ny < n) && (l[ny][nx] == 0)) {
        fill((nx << SHIFT) | ny);
      }
    }
  }

  public void run() throws Exception {
    n = nextInt();
    m = nextInt();

    l = new int [n][m];
    for (int i = 0; i < n; i++) {
      String s = next();
      for (int j = 0; j < m; j++) {
        l[i][j] = (s.charAt(j) == '.') ? 0 : -1;
      }
    }

    StringBuffer ans = new StringBuffer();

    for (int y = 0, k = 10; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] == 0) {
          f = new ArrayDeque();
          fill((x << SHIFT) | y);
          int kk = f.size() % 10;

          while (f.size() > 0) {
            int xy = f.pollFirst();
            l[xy & MASK][xy >>> SHIFT] = k + kk;
          }

          k += 10;
        }
      }
    }

    for (int y = 0; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] < 0) {
          int k = 1;
          BitSet lu = new BitSet();

          for (int [] dxdy : DXDY) {
            int nx = x + dxdy[0];
            int ny = y + dxdy[1];

            if ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n) && (l[ny][nx] > 0)) {
              int kk = l[ny][nx];

              if (!lu.get(kk / 10)) {
                lu.set(kk / 10);
                k += kk;
              }
            }
          }

          ans.append(k % 10);
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P616C().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int [][] DXDY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  final static int SHIFT = 10;
  final static int MASK = (1 << SHIFT) - 1;

  int n, m;
  int [][] l = null;
  ArrayDeque<Integer> f = null;

  void fill(int xy) {
    l[xy & MASK][xy >> SHIFT] = 1;
    f.addLast(xy);

    for (int [] dxdy : DXDY) {
      int nx = (xy >> SHIFT) + dxdy[0];
      int ny = (xy & MASK) + dxdy[1];

      if ((nx >= 0) && (nx < m) && (ny >= 0) && (ny < n) && (l[ny][nx] == 0)) {
        fill((nx << SHIFT) | ny);
      }
    }
  }

  public void run() throws Exception {
    n = nextInt();
    m = nextInt();

    l = new int [n][m];
    for (int i = 0; i < n; i++) {
      String s = next();
      for (int j = 0; j < m; j++) {
        l[i][j] = (s.charAt(j) == '.') ? 0 : -1;
      }
    }

    StringBuffer ans = new StringBuffer();

    for (int y = 0, k = 10; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] == 0) {
          f = new ArrayDeque();
          fill((x << SHIFT) | y);
          int kk = f.size() % 10;

          while (f.size() > 0) {
            int xy = f.pollFirst();
            l[xy & MASK][xy >>> SHIFT] = k + kk;
          }

          k += 10;
        }
      }
    }

    for (int y = 0; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] < 0) {
          int k = 1;
          BitSet lu = new BitSet();

          for (int [] dxdy : DXDY) {
            int nx = x + dxdy[0];
            int ny = y + dxdy[1];

            if ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n) && (l[ny][nx] > 0)) {
              int kk = l[ny][nx];

              if (!lu.get(kk / 10)) {
                lu.set(kk / 10);
                k += kk;
              }
            }
          }

          ans.append(k % 10);
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

  public static void main(String... args) throws Exception {
    new Thread(null, new Runnable() {
      public void run() {
        try {
          br = new BufferedReader(new InputStreamReader(System.in));
          pw = new PrintWriter(new BufferedOutputStream(System.out));
          new P616C().run();
          br.close();
          pw.close();
        } catch (Exception e) { System.err.println(e); }
      }
    }, "1", 1 << 27).start();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int [][] DXDY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  final static int SHIFT = 10;
  final static int MASK = (1 << SHIFT) - 1;

  int n, m;
  int [][] l = null;
  ArrayDeque<Integer> f = null;

  void fill(int xy) {
    l[xy & MASK][xy >> SHIFT] = 1;
    f.addLast(xy);

    for (int [] dxdy : DXDY) {
      int nx = (xy >> SHIFT) + dxdy[0];
      int ny = (xy & MASK) + dxdy[1];

      if ((nx >= 0) && (nx < m) && (ny >= 0) && (ny < n) && (l[ny][nx] == 0)) {
        fill((nx << SHIFT) | ny);
      }
    }
  }

  public void run() throws Exception {
    n = nextInt();
    m = nextInt();

    l = new int [n][m];
    for (int i = 0; i < n; i++) {
      String s = next();
      for (int j = 0; j < m; j++) {
        l[i][j] = (s.charAt(j) == '.') ? 0 : -1;
      }
    }

    StringBuffer ans = new StringBuffer();

    for (int y = 0, k = 10; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] == 0) {
          f = new ArrayDeque();
          fill((x << SHIFT) | y);
          int kk = f.size() % 10;

          while (f.size() > 0) {
            int xy = f.pollFirst();
            l[xy & MASK][xy >>> SHIFT] = k + kk;
          }

          k += 10;
        }
      }
    }

    for (int y = 0; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] < 0) {
          int k = 1;
          BitSet lu = new BitSet();

          for (int [] dxdy : DXDY) {
            int nx = x + dxdy[0];
            int ny = y + dxdy[1];

            if ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n) && (l[ny][nx] > 0)) {
              int kk = l[ny][nx];

              if (!lu.get(kk / 10)) {
                lu.set(kk / 10);
                k += kk;
              }
            }
          }

          ans.append(k % 10);
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

  public static void main(String... args) throws Exception {
    new Thread(null, new Runnable() {
      public void run() {
        try {
          br = new BufferedReader(new InputStreamReader(System.in));
          pw = new PrintWriter(new BufferedOutputStream(System.out));
          new P616C().run();
          br.close();
          pw.close();
        } catch (Exception e) { System.err.println(e); }
      }
    }, "1", 1 << 26).start();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P616C {

  final static int [][] DXDY = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

  int n, m;
  int [][] l = null;
  ArrayDeque<int []> f = null;

  void fill(int x, int y) {
    l[y][x] = 1;
    f.add(new int [] {x, y});

    for (int [] dxdy : DXDY) {
      int nx = x + dxdy[0];
      int ny = y + dxdy[1];

      if ((nx >= 0) && (nx < m) && (ny >= 0) && (ny < n) && (l[ny][nx] == 0)) {
        fill(nx, ny);
      }
    }
  }

  public void run() throws Exception {
    n = nextInt();
    m = nextInt();

    l = new int [n][m];
    for (int i = 0; i < n; i++) {
      String s = next();
      for (int j = 0; j < m; j++) {
        l[i][j] = (s.charAt(j) == '.') ? 0 : -1;
      }
    }

    StringBuffer ans = new StringBuffer(2 * n * m);

    for (int y = 0, k = 10; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] == 0) {
          f = new ArrayDeque();
          fill(x, y);
          int kk = f.size() % 10;

          while (f.size() > 0) {
            int [] xy = f.pollFirst();
            l[xy[1]][xy[0]] = k + kk;
          }

          k += 10;
        }
      }
    }

    for (int y = 0; y < n; y++) {
      for (int x = 0; x < m; x++) {
        if (l[y][x] < 0) {
          int k = 1;
          BitSet lu = new BitSet();

          for (int [] dxdy : DXDY) {
            int nx = x + dxdy[0];
            int ny = y + dxdy[1];

            if ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n) && (l[ny][nx] > 0)) {
              int kk = l[ny][nx];

              if (!lu.get(kk / 10)) {
                lu.set(kk / 10);
                k += kk;
              }
            }
          }

          ans.append(k % 10);
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P616C().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        int[] dx = new int[]{-1, 0, 1, 0};
        int[] dy = new int[]{0, -1, 0, 1};
        char[][] map;
        int n;
        int m;
        int N;
        int[] size;
        int[][] id;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            map = new char[n][];
            for (int i = 0; i < n; ++i) {
                map[i] = in.next().toCharArray();
            }
            N = 0;
            size = new int[n * m];
            id = new int[n][m];
            for (int i = 0; i < n; ++i) {
                Arrays.fill(id[i], -1);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '.' && id[i][j] == -1) {
                        go(i, j);
                        ++N;
                    }
                }
            }
            int[][] ans = new int[n][m];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        ArrayList<Integer> adj = new ArrayList<>();
                        for (int k = 0; k < 4; ++k) {
                            int xx = i + dx[k], yy = j + dy[k];
                            if (xx >= 0 && xx < n && yy >= 0 && yy < m && id[xx][yy] >= 0) {
                                adj.add(id[xx][yy]);
                            }
                        }
                        Collections.sort(adj);
                        ans[i][j] = 1;
                        for (int k = 0; k < adj.size(); ++k) {
                            if (k == 0 || adj.get(k - 1) != adj.get(k)) {
                                ans[i][j] += size[adj.get(k)];
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        map[i][j] = (char) ('0' + ans[i][j] % 10);
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                out.println(map[i]);
            }
        }

        void go(int x, int y) {
            id[x][y] = N;
            ++size[N];
            for (int i = 0; i < 4; ++i) {
                int xx = x + dx[i], yy = y + dy[i];
                if (xx >= 0 && xx < n && yy >= 0 && yy < m && map[xx][yy] == '.' && id[xx][yy] == -1) {
                    go(xx, yy);
                }
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        int[] dx = new int[]{-1, 0, 1, 0};
        int[] dy = new int[]{0, -1, 0, 1};
        char[][] map;
        int n;
        int m;
        int N;
        int[] size;
        int[][] id;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            map = new char[n][];
            for (int i = 0; i < n; ++i) {
                map[i] = in.next().toCharArray();
            }
            N = 0;
            size = new int[n * m];
            id = new int[n][m];
            for (int i = 0; i < n; ++i) {
                Arrays.fill(id[i], -1);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '.' && id[i][j] == -1) {
                        go(i, j);
                        ++N;
                    }
                }
            }
            int[][] ans = new int[n][m];
            boolean[] mk = new boolean[N];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        ArrayList<Integer> adj = new ArrayList<>();
                        for (int k = 0; k < 4; ++k) {
                            int xx = i + dx[k], yy = j + dy[k];
                            if (xx >= 0 && xx < n && yy >= 0 && yy < m && id[xx][yy] >= 0) {
                                assert (map[xx][yy] == '.');
                                adj.add(id[xx][yy]);
                            }
                        }
                        ans[i][j] = 1;
                        for (int k = 0; k < adj.size(); ++k) {
                            int t = adj.get(k);
                            if (!mk[t]) {
                                mk[t] = true;
                                ans[i][j] += size[t];
                            }
                        }
                        for (int k = 0; k < adj.size(); ++k) {
                            mk[adj.get(k)] = false;
                        }
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        map[i][j] = (char) ('0' + ans[i][j] % 10);
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                out.println(map[i]);
            }
        }

        void go(int x, int y) {
            id[x][y] = N;
            ++size[N];
            for (int i = 0; i < 4; ++i) {
                int xx = x + dx[i], yy = y + dy[i];
                if (xx >= 0 && xx < n && yy >= 0 && yy < m && map[xx][yy] == '.' && id[xx][yy] == -1) {
                    go(xx, yy);
                }
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        int[] dx = new int[]{-1, 0, 1, 0};
        int[] dy = new int[]{0, -1, 0, 1};
        char[][] map;
        int n;
        int m;
        int N;
        int[] size;
        int[][] id;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            map = new char[n][];
            for (int i = 0; i < n; ++i) {
                map[i] = in.next().toCharArray();
            }
            N = 0;
            size = new int[n * m];
            id = new int[n][m];
            for (int i = 0; i < n; ++i) {
                Arrays.fill(id[i], -1);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '.' && id[i][j] == -1) {
                        go(i, j);
                        ++N;
                    }
                }
            }
            int[][] ans = new int[n][m];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        ArrayList<Integer> adj = new ArrayList<>();
                        for (int k = 0; k < 4; ++k) {
                            int xx = i + dx[k], yy = j + dy[k];
                            if (xx >= 0 && xx < n && yy >= 0 && yy < m && id[xx][yy] >= 0) {
                                assert (map[xx][yy] == '.');
                                adj.add(id[xx][yy]);
                            }
                        }
                        ans[i][j] = 1;
                        Collections.sort(adj, new Comparator<Integer>() {

                            public int compare(Integer o1, Integer o2) {
                                return o1 - o2;
                            }
                        });
                        for (int k = 0; k < adj.size(); ++k) {
                            assert (adj.get(k - 1) <= adj.get(k));
                        }
                        for (int k = 0; k < adj.size(); ++k) {
                            if (k == 0 || adj.get(k - 1) != adj.get(k)) {
                                ans[i][j] += size[adj.get(k)];
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        map[i][j] = (char) ('0' + ans[i][j] % 10);
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                out.println(map[i]);
            }
        }

        void go(int x, int y) {
            id[x][y] = N;
            ++size[N];
            for (int i = 0; i < 4; ++i) {
                int xx = x + dx[i], yy = y + dy[i];
                if (xx >= 0 && xx < n && yy >= 0 && yy < m && map[xx][yy] == '.' && id[xx][yy] == -1) {
                    go(xx, yy);
                }
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            char[][] map = new char[n][];
            for (int i = 0; i < n; ++i) {
                map[i] = in.next().toCharArray();
            }
            int N = 0;
            int[] size = new int[n * m];
            int[][] id = new int[n][m];
            for (int i = 0; i < n; ++i) {
                Arrays.fill(id[i], -1);
            }
            int[] q = new int[n * m];
            int[] dx = new int[]{-1, 0, 1, 0};
            int[] dy = new int[]{0, -1, 0, 1};
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '.' && id[i][j] == -1) {
                        q[0] = i * m + j;
                        id[i][j] = N;
                        size[N] = 1;
                        for (int h = 0, t = 1; h < t; ++h) {
                            int x = q[h] / m, y = q[h] % m;
                            for (int k = 0; k < 4; ++k) {
                                int xx = x + dx[k], yy = y + dy[k];
                                if (xx >= 0 && xx < n && yy >= 0 && yy < m && map[xx][yy] == '.' && id[xx][yy] == -1) {
                                    q[t++] = xx * m + yy;
                                    id[xx][yy] = N;
                                    ++size[N];
                                }
                            }
                        }
                        ++N;
                    }
                }
            }
            int[][] ans = new int[n][m];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        ArrayList<Integer> adj = new ArrayList<>();
                        for (int k = 0; k < 4; ++k) {
                            int xx = i + dx[k], yy = j + dy[k];
                            if (xx >= 0 && xx < n && yy >= 0 && yy < m && id[xx][yy] >= 0) {
                                adj.add(id[xx][yy]);
                            }
                        }
                        Collections.sort(adj);
                        ans[i][j] = 1;
                        for (int k = 0; k < adj.size(); ) {
                            int t = k + 1;
                            while (t < adj.size() && adj.get(k) == adj.get(t)) {
                                ++t;
                            }
                            ans[i][j] = (ans[i][j] + size[adj.get(k)]) % 10;
                            k = t;
                        }
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        map[i][j] = (char) ('0' + ans[i][j]);
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                out.println(map[i]);
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        int[] dx = new int[]{-1, 0, 1, 0};
        int[] dy = new int[]{0, -1, 0, 1};
        char[][] map;
        int n;
        int m;
        int N;
        int[] size;
        int[][] id;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            map = new char[n][];
            for (int i = 0; i < n; ++i) {
                map[i] = in.next().toCharArray();
            }
            N = 0;
            size = new int[n * m];
            id = new int[n][m];
            for (int i = 0; i < n; ++i) {
                Arrays.fill(id[i], -1);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '.' && id[i][j] == -1) {
                        go(i, j);
                        ++N;
                    }
                }
            }
            int[][] ans = new int[n][m];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        ArrayList<Integer> adj = new ArrayList<>();
                        for (int k = 0; k < 4; ++k) {
                            int xx = i + dx[k], yy = j + dy[k];
                            if (xx >= 0 && xx < n && yy >= 0 && yy < m && id[xx][yy] >= 0) {
                                assert (map[xx][yy] == '.');
                                adj.add(id[xx][yy]);
                            }
                        }
                        Collections.sort(adj);
                        ans[i][j] = 1;
                        for (int k = 0; k < adj.size(); ++k) {
                            if (k == 0 || adj.get(k - 1) != adj.get(k)) {
                                ans[i][j] += size[adj.get(k)];
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        map[i][j] = (char) ('0' + ans[i][j] % 10);
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                out.println(map[i]);
            }
        }

        void go(int x, int y) {
            id[x][y] = N;
            ++size[N];
            for (int i = 0; i < 4; ++i) {
                int xx = x + dx[i], yy = y + dy[i];
                if (xx >= 0 && xx < n && yy >= 0 && yy < m && map[xx][yy] == '.' && id[xx][yy] == -1) {
                    go(xx, yy);
                }
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            char[][] map = new char[n][];
            for (int i = 0; i < n; ++i) {
                map[i] = in.next().toCharArray();
            }
            int N = 0;
            int[] size = new int[n * m];
            int[][] id = new int[n][m];
            for (int i = 0; i < n; ++i) {
                Arrays.fill(id[i], -1);
            }
            int[] q = new int[n * m];
            int[] dx = new int[]{-1, 0, 1, 0};
            int[] dy = new int[]{0, -1, 0, 1};
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '.' && id[i][j] == -1) {
                        q[0] = i * m + j;
                        id[i][j] = N;
                        size[N] = 1;
                        for (int h = 0, t = 1; h < t; ++h) {
                            int x = q[h] / m, y = q[h] % m;
                            for (int k = 0; k < 4; ++k) {
                                int xx = x + dx[k], yy = y + dy[k];
                                if (xx >= 0 && xx < n && yy >= 0 && yy < m && map[xx][yy] == '.' && id[xx][yy] == -1) {
                                    q[t++] = xx * m + yy;
                                    id[xx][yy] = N;
                                    ++size[N];
                                }
                            }
                        }
                        ++N;
                    }
                }
            }
            int[][] ans = new int[n][m];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        ArrayList<Integer> adj = new ArrayList<>();
                        for (int k = 0; k < 4; ++k) {
                            int xx = i + dx[k], yy = j + dy[k];
                            if (xx >= 0 && xx < n && yy >= 0 && yy < m && id[xx][yy] >= 0) {
                                adj.add(id[xx][yy]);
                                System.err.println(id[xx][yy]);
                            }
                        }
                        Collections.sort(adj);
                        ans[i][j] = 1;
                        for (int k = 0; k < adj.size(); ) {
                            int t = k + 1;
                            while (t < adj.size() && adj.get(k) == adj.get(t)) {
                                ++t;
                            }
                            ans[i][j] = (ans[i][j] + size[adj.get(k)]) % 10;
                            k = t;
                        }
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        out.print(ans[i][j]);
                    } else {
                        out.print(".");
                    }
                }
                out.println("");
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        int[] dx = new int[]{-1, 0, 1, 0};
        int[] dy = new int[]{0, -1, 0, 1};
        char[][] map;
        int n;
        int m;
        int N;
        int[] size;
        int[][] id;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            map = new char[n][];
            for (int i = 0; i < n; ++i) {
                map[i] = in.next().toCharArray();
            }
            N = 0;
            size = new int[n * m];
            id = new int[n][m];
            for (int i = 0; i < n; ++i) {
                Arrays.fill(id[i], -1);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '.' && id[i][j] == -1) {
                        go(i, j);
                        ++N;
                    }
                }
            }
            int[][] ans = new int[n][m];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        ArrayList<Integer> adj = new ArrayList<>();
                        for (int k = 0; k < 4; ++k) {
                            int xx = i + dx[k], yy = j + dy[k];
                            if (xx >= 0 && xx < n && yy >= 0 && yy < m && id[xx][yy] >= 0) {
                                assert (map[xx][yy] == '.');
                                adj.add(id[xx][yy]);
                            }
                        }
                        ans[i][j] = 1;
                        Collections.sort(adj);
                        for (int k = 0; k < adj.size(); ++k) {
                            assert (adj.get(k - 1) <= adj.get(k));
                        }
                        for (int k = 0; k < adj.size(); ++k) {
                            if (k == 0 || adj.get(k - 1) != adj.get(k)) {
                                ans[i][j] += size[adj.get(k)];
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (map[i][j] == '*') {
                        map[i][j] = (char) ('0' + ans[i][j] % 10);
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                out.println(map[i]);
            }
        }

        void go(int x, int y) {
            id[x][y] = N;
            ++size[N];
            for (int i = 0; i < 4; ++i) {
                int xx = x + dx[i], yy = y + dy[i];
                if (xx >= 0 && xx < n && yy >= 0 && yy < m && map[xx][yy] == '.' && id[xx][yy] == -1) {
                    go(xx, yy);
                }
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {

    static int n, m;
    static char[][] g;
    static int[][][] mem;
    static int[][] rem;
    static boolean[][] v;

    static int[] dr = {0, 0, 1, -1};
    static int[] dc = {1, -1, 0, 0};

    static int DFS(int r, int c, int id, int jd) {
        if (v[r][c]) {
            return 0;
        }
        v[r][c] = true;
        mem[r][c][0] = id;
        mem[r][c][1] = jd;
        int ret = 1;
        for (int i = 0; i < 4; i++) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            if (nr < 0 || nr >= n || nc < 0 || nc >= m) {
                continue;
            }
            if (g[nr][nc] != '.') {
                continue;
            }
            ret += DFS(nr, nc, id, jd);
        }
        return ret;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        String[] ar;
        StringBuilder sb = new StringBuilder();
        //-----------------------------------------------------------------------
        ar = br.readLine().split(" ");
        n = Integer.parseInt(ar[0]);
        m = Integer.parseInt(ar[1]);
        g = new char[n][m];
        mem = new int[n][m][2];
        rem = new int[n][m];
        v = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            g[i] = br.readLine().toCharArray();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                mem[i][j][0] = -1;
                mem[i][j][1] = -1;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (g[i][j] == '.' && !v[i][j]) {
                    rem[i][j] = DFS(i, j, i, j);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (g[i][j] == '*') {
                    rem[i][j] = 1;
                    ArrayList<Integer> r = new ArrayList();
                    ArrayList<Integer> c = new ArrayList();
                    for (int k = 0; k < 4; k++) {
                        int ni = i + dr[k];
                        int nj = j + dc[k];
                        if (ni < 0 || ni >= n || nj < 0 || nj >= m) {
                            continue;
                        }
                        if (g[ni][nj] == '.') {
                            boolean b = false;
                            for (int l = 0; l < r.size(); l++) {
                                if (r.get(l) == mem[ni][nj][0] && c.get(l) == mem[ni][nj][1]) {
                                    b = true;
                                }
                            }
                            if (!b) {
                                rem[i][j] += rem[mem[ni][nj][0]][mem[ni][nj][1]];
                                r.add(mem[ni][nj][0]);
                                c.add(mem[ni][nj][1]);
                            }
                        }
                    }
                    g[i][j] = (char) (rem[i][j] % 10 + '0');
                }
                sb.append(g[i][j]);
            }
            sb.append("\n");
        }
        //-----------------------------------------------------------------------
        System.out.print(sb);
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {

    static int n, m;
    static char[][] g;
    static int[][][] mem;
    static int[][] rem;
    static boolean[][] v;

    static int[] dr = {0, 0, 1, -1};
    static int[] dc = {1, -1, 0, 0};

    static int DFS(int r, int c, int id, int jd) {
        if (v[r][c]) {
            return 0;
        }
        v[r][c] = true;
        mem[r][c][0] = id;
        mem[r][c][1] = jd;
        int ret = 1;
        for (int i = 0; i < 4; i++) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            if (nr < 0 || nr >= n || nc < 0 || nc >= m) {
                continue;
            }
            if (g[nr][nc] != '.') {
                continue;
            }
            ret += DFS(nr, nc, id, jd);
        }
        return ret;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        String[] ar;
        StringBuilder sb = new StringBuilder();
        //-----------------------------------------------------------------------
        ar = br.readLine().split(" ");
        n = Integer.parseInt(ar[0]);
        m = Integer.parseInt(ar[1]);
        g = new char[n][m];
        mem = new int[n][m][2];
        rem = new int[n][m];
        v = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            g[i] = br.readLine().toCharArray();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                mem[i][j][0] = -1;
                mem[i][j][1] = -1;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (g[i][j] == '.' && !v[i][j]) {
                    rem[i][j] = DFS(i, j, i, j);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (g[i][j] == '*') {
                    rem[i][j] = 1;
                    ArrayList<Integer> r = new ArrayList();
                    ArrayList<Integer> c = new ArrayList();
                    for (int k = 0; k < 4; k++) {
                        int ni = i + dr[k];
                        int nj = j + dc[k];
                        if (ni < 0 || ni >= n || nj < 0 || nj >= m) {
                            continue;
                        }
                        if (g[ni][nj] == '.') {
                            boolean b = false;
                            for (int l = 0; l < r.size(); l++) {
                                if (r.get(l) == mem[ni][nj][0] && c.get(l) == mem[ni][nj][1]) {
                                    b = true;
                                }
                            }
                            if (!b) {
                                rem[i][j] += rem[mem[ni][nj][0]][mem[ni][nj][1]];
                                r.add(mem[ni][nj][0]);
                                c.add(mem[ni][nj][1]);
                            }
                        }
                    }
                    g[i][j] = (char) (rem[i][j] % 10 + '0');
                }
                sb.append(g[i][j]);
            }
            sb.append("\n");
        }
        //-----------------------------------------------------------------------
        System.out.print(sb);
    }
}


import java.util.*;
public class C616_TheLabyrinth {
	static Scanner sc = new Scanner(System.in);
	static Queue<Integer> q = new ArrayDeque<Integer>();
	public static void main(String[] args) {

		int n = sc.nextInt();
		int m = sc.nextInt();
		char[][] maze = new char[n][m];
		boolean[][] visited = new boolean[n][m];
		int hash = 100000, result = 1;

		sc.nextLine();
		for (int i=0; i<n; i++) {
			String nl = sc.nextLine();
			for (int j=0; j<m; j++) {
				maze[i][j] = nl.charAt(j);
				if (maze[i][j] == '*')
					visited[i][j] = true;
			}
		}

		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
//				System.out.println("NEXT");
				result = 0;
				if (maze[i][j] == '.') {
					System.out.print(".");
					continue;
				}

				for (int a=0; a<n; a++) {
					for (int b=0; b<m; b++) {
						if (maze[a][b] == '.')
							visited[a][b] = false;
						else
							visited[a][b] = true;
					}
				}
				q.add(hash*i+j);

				while(!q.isEmpty()) {
					int next = q.poll();
					result++;
//					System.out.println("Added: " + i + " " + j + ", result equals " + result);
					check(next, visited, n, m, hash, result);
				}
//				System.out.println("Printing result: " + result);
				System.out.print(result);
			}
			System.out.println();
		}
	}

	public static int check(int next, boolean[][] visited, int n, int m, int hash, int result) {
		int[] x = {0, 1, 0, -1};
		int[] y = {1, 0, -1, 0};
		int I = next/hash;
		int J = next%hash;
		for (int i=0; i<4; i++) {
			I += x[i];
			J += y[i];
//			System.out.println(I + " " + J);

			if (I>=0 && J>=0 && J<m && I<n && visited[I][J] == false) {
				q.add(I*hash+J);
				visited[I][J] = true;
			}
			I -= x[i];
			J -= y[i];
		}
		return 71901;
	}
}


import java.io.*;
import java.util.*;
public class C0616_TheLabyrinth {

	static int[][] grid;
	static final int[] x = {1, 0, -1, 0};
	static final int[] y = {0, 1, 0, -1};

	static class Point {
		public int X;
		public int Y;

		public Point(int x, int y) {
			X = x;
			Y = y;
		}
	}

	public static void main(String[] args) {
		InputReader in = new InputReader();
		int rows = in.nextInt();
		int cols = in.nextInt();

		grid = new int[rows + 2][cols + 2];
		addBoundary(rows, cols);

		for (int i=1; i<=rows; i++) {
			String line = in.next();
			for (int j=1; j<=cols; j++) {
				if (line.charAt(j-1) == '*')
					grid[i][j] = -1;
			}
		}

		int numRegions = 0;
		ArrayList<Integer> regions = new ArrayList<>();
		regions.add(-1); // make regions 1-indexed

		for (int i=1; i<=rows; i++) {
			for (int j=1; j<=cols; j++) if (grid[i][j] == 0) {
				Point p = new Point(i, j);
				regionSize = 0;
				floodFill(p, ++numRegions, rows, cols);
				regions.add(regionSize);
			}
		}

		StringBuffer sb = new StringBuffer();
		for (int i=1; i<=rows; i++) {
			for (int j=1; j<=cols; j++) {
				if (grid[i][j] != -1) {
					sb.append(".");
					continue;
				}
				ArrayList<Integer> adj = new ArrayList<>();
				for (int k=0; k<4; k++) {
					int I = i+x[k];
					int J = j+y[k];
					int group = grid[I][J];
					if (group != -1 && !adj.contains(group))
						adj.add(group);
				}
				int res = 1;
				for (int k: adj)
					res +=  regions.get(k);
				sb.append(res % 10);
			}
			sb.append("\n");
		}
		System.out.println(sb);
	}

	static int regionSize;
	public static void floodFill(Point p, int index, int rows, int cols) {
		grid[p.X][p.Y] = index;
		regionSize++;

		for (int i=0; i<4; i++) {
			int I = p.X + x[i];
			int J = p.Y + y[i];

			if (grid[I][J] == 0) {
				Point point = new Point(I, J);
				floodFill(point, index, rows, cols);
			}
		}
	}

	public static void addBoundary(int rows, int cols) {
		for (int i=0; i<rows+2; i++) {
			grid[i][0] = -1;
			grid[i][cols+1] = -1;
		}
		for (int j=0; j<cols+2; j++) {
			grid[0][j]= -1;
			grid[rows+1][j] = -1;
		}
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;

		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.util.*;
public class labyrinthtrial2 {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {

		int rows = sc.nextInt();
		int cols = sc.nextInt();

		Queue<Integer> q = new ArrayDeque<Integer>();
		String[][] strs = new String[rows][cols];
		boolean[][] done = new boolean[rows][cols];

		for (int i=0; i<rows; i++) {
			String str = sc.next();
			for (int j=0; j<cols; j++) {
				String next = str.substring(j, j+1);
				if (next.equals("*"))
					strs[i][j] = "1";
				else
					strs[i][j] = next;
			}
		}

		for (int i=0; i<rows; i++) {
			for (int j=0; j<cols; j++) {
				if (strs[i][j].equals(".") && !done[i][j]) {
					q.add(10000*i+j);
					done[i][j] = true;
					queue(q, strs, done, rows, cols);

				}
			}
		}

		for (int i=0; i<rows; i++) {
			for (int j=0; j<cols; j++) {
				System.out.print(strs[i][j]);
			}
			System.out.println();
		}
	}

	public static boolean queue(Queue<Integer> q, String[][] strs, boolean[][] done, int rows, int cols) {
		int[] x = {0, 1, 0, -1};
		int[] y = {1, 0, -1, 0};
		boolean[][] ToAdd = new boolean[rows][cols];
		int count = 1;

		while(!q.isEmpty()) {
			int next = q.poll();
			int I = next/10000;
			int J = next%10000;
			for (int i=0; i<4; i++) {
				I += x[i];
				J += y[i];
				if (I>=0 && I<rows && J>=0 && J<cols) {
					if (strs[I][J].equals(".")) {
						if (!done[I][J]) {
							count++;
							q.add(10000*I+J);
							done[I][J] = true;
						}
					}
					else
						ToAdd[I][J] = true;
				}
				I -= x[i];
				J -= y[i];
			}
		}
		AddInts(ToAdd, strs, count, rows, cols);
		return false;
	}

	public static boolean AddInts(boolean[][] ToAdd, String[][] strs, int count, int rows, int cols) {
		for (int i=0; i<rows; i++) {
			for (int j=0; j<cols; j++) {
				if (ToAdd[i][j]) {
					String place = strs[i][j];
					int bc = Integer.parseInt(place);
					bc += count;
					if (bc >= 10)
						bc %= 10;
					String newplace = Integer.toString(bc);
					strs[i][j] = newplace;
				}
			}
		}
		return false;
	}
}


import java.io.*;
import java.util.*;
public class C616_TheLabyrinth {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args) throws IOException {

		OutputStream outputStream = System.out;
		PrintWriter pw = new PrintWriter(outputStream);
		String nums = br.readLine();
		int rows = Integer.parseInt(nums.substring(0, nums.indexOf(' ')));
		int cols = Integer.parseInt(nums.substring(nums.indexOf(' ')+1));

		Queue<Integer> q = new ArrayDeque<Integer>();
		String[][] strs = new String[rows][cols];
		boolean[][] done = new boolean[rows][cols];

		for (int i=0; i<rows; i++) {
			String str = br.readLine();
			for (int j=0; j<cols; j++) {
				String next = str.substring(j, j+1);
				if (next.equals("*"))
					strs[i][j] = "1";
				else
					strs[i][j] = next;
			}
		}

		for (int i=0; i<rows; i++) {
			for (int j=0; j<cols; j++) {
				if (strs[i][j].equals(".") && !done[i][j]) {
					q.add(10000*i+j);
					done[i][j] = true;
					queue(q, strs, done, rows, cols);

				}
			}
		}

		for (int i=0; i<rows; i++) {
			for (int j=0; j<cols; j++) {
				pw.print(strs[i][j]);
			}
			pw.println();
		}

		pw.close();
	}

	public static boolean queue(Queue<Integer> q, String[][] strs, boolean[][] done, int rows, int cols) {
		int[] x = {0, 1, 0, -1};
		int[] y = {1, 0, -1, 0};
		boolean[][] ToAdd = new boolean[rows][cols];
		int count = 1;

		while(!q.isEmpty()) {
			int next = q.poll();
			int I = next/10000;
			int J = next%10000;
			for (int i=0; i<4; i++) {
				I += x[i];
				J += y[i];
				if (I>=0 && I<rows && J>=0 && J<cols) {
					if (strs[I][J].equals(".")) {
						if (!done[I][J]) {
							count++;
							q.add(10000*I+J);
							done[I][J] = true;
						}
					}
					else
						ToAdd[I][J] = true;
				}
				I -= x[i];
				J -= y[i];
			}
		}
		AddInts(ToAdd, strs, count, rows, cols);
		return false;
	}

	public static boolean AddInts(boolean[][] ToAdd, String[][] strs, int count, int rows, int cols) {
		for (int i=0; i<rows; i++) {
			for (int j=0; j<cols; j++) {
				if (ToAdd[i][j]) {
					String place = strs[i][j];
					int bc = Integer.parseInt(place);
					bc += count;
					if (bc >= 10)
						bc %= 10;
					String newplace = Integer.toString(bc);
					strs[i][j] = newplace;
				}
			}
		}
		return false;
	}
}


import java.io.*;
import java.util.*;
public class C0616_TheLabyrinth {

	static int rows, cols;
	static int[][] grid;
	static final int[] x = {1, 0, -1, 0};
	static final int[] y = {0, 1, 0, -1};

	public static void main(String[] args) {
		InputReader in = new InputReader();
		rows = in.nextInt();
		cols = in.nextInt();

		grid = new int[rows + 2][cols + 2];
		addBoundary();

		for (int i=1; i<=rows; i++) {
			String line = in.next();
			for (int j=1; j<=cols; j++) {
				if (line.charAt(j-1) == '*')
					grid[i][j] = -1;
			}
		}

		int numRegions = 0;
		ArrayList<Integer> regions = new ArrayList<>();
		regions.add(-1); // make regions 1-indexed

		for (int i=1; i<=rows; i++) {
			for (int j=1; j<=cols; j++) if (grid[i][j] == 0) {
				regionSize = 0;
				floodFill(i, j, ++numRegions);
				regions.add(regionSize);
			}
		}

		StringBuffer sb = new StringBuffer();
		for (int i=1; i<=rows; i++) {
			for (int j=1; j<=cols; j++) {
				if (grid[i][j] != -1) {
					sb.append(".");
					continue;
				}
				ArrayList<Integer> adj = new ArrayList<>();
				for (int k=0; k<4; k++) {
					int I = i+x[k];
					int J = j+y[k];
					int group = grid[I][J];
					if (group != -1 && !adj.contains(group))
						adj.add(group);
				}
				int res = 1;
				for (int k: adj)
					res +=  regions.get(k);
				sb.append(res % 10);
			}
			sb.append("\n");
		}
		System.out.println(sb);
	}

	static int regionSize;
	public static void floodFill(int i, int j, int index) {
		grid[i][j] = index;
		++regionSize;

		for (int a=0; a<4; a++) {
			int I = i + x[a];
			int J = j + y[a];

			if (grid[I][J] == 0) {
				floodFill(I, J, index);
			}
		}
	}

	public static void addBoundary() {
		for (int i=0; i<rows+2; i++) {
			grid[i][0] = -1;
			grid[i][cols+1] = -1;
		}
		for (int j=0; j<cols+2; j++) {
			grid[0][j]= -1;
			grid[rows+1][j] = -1;
		}
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;

		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}