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);
				for (;;) {
					if (result>9)
						result %= 10;
					else
						break;
				}
				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.math.*;
import java.util.*;

/**
 *
 * @author Saju
 *
 */

public class Main {

    private static int dx[] = { 1, 0, -1, 0 };
    private static int dy[] = { 0, -1, 0, 1 };

    private static final long INF = Long.MAX_VALUE;
    private static final int INT_INF = Integer.MAX_VALUE;
    private static final long NEG_INF = Long.MIN_VALUE;
    private static final int NEG_INT_INF = Integer.MIN_VALUE;
    private static final double EPSILON = 1e-10;

    private static final long MAX = (long) 1e12;

    private static final long MOD = 100000007;

    private static final int MAXN = 300005;
    private static final int MAXA = 200007;
    private static final int MAXLOG = 22;
    private static final double PI = Math.acos(-1);

	public static void main(String[] args) throws IOException {

		InputReader in = new InputReader(System.in);
//		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

//         InputReader in = new InputReader(new FileInputStream("src/test.in"));
//         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));

/*

*/

		int n =  in.nextInt();
		int m = in.nextInt();
		char[][] grid = new char[n][m];
		for(int i = 0; i < n; i++) {
			grid[i] = in.next().toCharArray();
		}
		boolean[][] visited = new boolean[n][m];
		ci = 0;
		int[][] components = new int[n][m];
		int[] cnt = new int[(n * m) + 5];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(grid[i][j] == '.' && !visited[i][j]) {
					ci++;
					c = 0;
					dfs(i, j, n, m, grid, visited, components);
					cnt[ci] = c;
				}
			}
		}

//		for(int i = 0; i < n; i++) {
//			for(int j = 0; j < m; j++) {
//				System.out.print("(" + cnt[i][j].ci + " " + cnt[i][j].c + ")");
//			}
//			System.out.println();
//		}

		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(grid[i][j] == '.') {
					sb.append(".");
				}
				else {
					int c = 0;
					List<Integer> list = new ArrayList<>();
					for(int k = 0; k < 4; k++) {
						int p = i + dx[k];
						int q = j + dy[k];
						if(p >= 0 && p < n && q >= 0 && q < m && grid[p][q] == '.') {
							if(!list.contains(components[p][q])) {
								list.add(components[p][q]);
								c += cnt[components[p][q]];
							}
						}
					}
					sb.append(((c + 1) % 10)+"");
				}
			}
			sb.append("\n");
		}
		out.print(sb.toString());

		in.close();
		out.flush();
		out.close();
		System.exit(0);
	}

	private static int c = 0;
	private static int ci = 0;
	private static void dfs(int ui, int uj, int n, int m, char[][] grid, boolean[][] visited, int[][] components) {
		c++;
		visited[ui][uj] = true;
		components[ui][uj] = ci;
		for(int i = 0; i < 4; i++) {
			int vi = ui + dx[i];
			int vj = uj + dy[i];
			if(vi >= 0 && vi < n && vj >= 0 && vj < m && grid[vi][vj] == '.' && !visited[vi][vj]) {
				dfs(vi, vj, n, m, grid, visited, components);
			}
		}
	}

	private static class Pair{
		int ci;
		int c;
		public Pair(){
			ci = 0;
			c = 0;
		}
	}

	/*
	 * return the number of elements in list that are less than or equal to the val
	 */
	private static long upperBound(List<Long> list, long val) {
		int start = 0;
		int len = list.size();
		int end = len - 1;
		int mid = 0;

		while (true) {
			if (start > end) {
				break;
			}
			mid = (start + end) / 2;
			long v = list.get(mid);
			if (v == val) {
				start = mid;
				while(start < end) {
					mid = (start + end) / 2;
					if(list.get(mid) == val) {
						if(mid + 1 < len && list.get(mid + 1) == val) {
							start = mid + 1;
						}
						else {
							return mid + 1;
						}
					}
					else {
						end = mid - 1;
					}
				}
				return start + 1;
			}
			if (v > val) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
		}
		if (list.get(mid) < val) {
			return mid + 1;
		}
		return mid;
	}

	private static boolean isPalindrome(String str) {
		StringBuilder sb = new StringBuilder();
		sb.append(str);
		String str1 = sb.reverse().toString();
		return str.equals(str1);
	}

	private static String getBinaryStr(long n, int j) {
		String str = Long.toBinaryString(n);
		int k = str.length();
		for (int i = 1; i <= j - k; i++) {
			str = "0" + str;
		}

		return str;
	}

	private static long modInverse(long r) {
		return bigMod(r, MOD - 2, MOD);
	}

	private static long bigMod(long n, long k, long m) {

        long ans = 1;
        while (k > 0) {
            if ((k & 1) == 1) {
                ans = (ans * n) % m;
            }
            n = (n * n) % m;
            k >>= 1;
        }
        return ans;
    }

	private static long ceil(long n, long x) {
		long div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
	}

    private static int ceil(int n, int x) {
        int div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
    }

    private static int abs(int x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static double abs(double x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static long abs(long x) {
        if(x < 0) {
            return -x;
        }
        return x;
    }

    private static int lcm(int a, int b) {
        return (a * b) / gcd(a, b);
    }

    private static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static long gcd(long a, long b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static int log(long x, int base) {
        return (int) (Math.log(x) / Math.log(base));
    }

    private static long min(long a, long b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static int min(int a, int b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static long max(long a, long b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static int max(int a, int b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());

                }
            } catch (IOException e) {
                return null;
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = null;
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public boolean hasNext() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (Exception e) {
                return false;
            }
            return true;
        }

        public int[] nextIntArr(int n) {
        	int arr[] = new int[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr(int n) {
        	long arr[] = new long[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public int[] nextIntArr1(int n) {
        	int arr[] = new int[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr1(int n) {
        	long arr[] = new long[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public void close() {
        	try {
        		if(reader != null) {
        			reader.close();
        		}
        	}
        	catch(Exception e) {

        	}

        }
    }

}


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

/**
 *
 * @author Saju
 *
 */

public class Main {

    private static int dx[] = { 1, 0, -1, 0 };
    private static int dy[] = { 0, -1, 0, 1 };

    private static final long INF = Long.MAX_VALUE;
    private static final int INT_INF = Integer.MAX_VALUE;
    private static final long NEG_INF = Long.MIN_VALUE;
    private static final int NEG_INT_INF = Integer.MIN_VALUE;
    private static final double EPSILON = 1e-10;

    private static final long MAX = (long) 1e12;

    private static final long MOD = 100000007;

    private static final int MAXN = 300005;
    private static final int MAXA = 200007;
    private static final int MAXLOG = 22;
    private static final double PI = Math.acos(-1);

	public static void main(String[] args) throws IOException {

		InputReader in = new InputReader(System.in);
//		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

//         InputReader in = new InputReader(new FileInputStream("src/test.in"));
//         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));

/*

*/

		int n =  in.nextInt();
		int m = in.nextInt();
		char[][] grid = new char[n][m];
		char[][] ans = new char[n][m];
		for(int i = 0; i < n; i++) {
			grid[i] = in.next().toCharArray();
		}
		boolean[][] visited = new boolean[n][m];
		boolean[][] visited1 = new boolean[n][m];
//		Pair[][] cnt = new Pair[n][m];
//		for(int i = 0; i < n; i++) {
//			for(int j = 0; j < m; j++) {
//				cnt[i][j] = new Pair();
//			}
//		}
		ci = 0;
		int[][] components = new int[n][m];
		int[] cnt = new int[(n * m) + 5];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(grid[i][j] == '.' && !visited[i][j]) {
					ci++;
					c = 0;
					dfs(i, j, n, m, grid, visited, components);
					cnt[ci] = c;
//					System.out.println(c);
//					dfs1(i, j, n, m, grid, visited1, cnt);
				}
			}
		}

//		for(int i = 0; i < n; i++) {
//			for(int j = 0; j < m; j++) {
//				System.out.print("(" + cnt[i][j].ci + " " + cnt[i][j].c + ")");
//			}
//			System.out.println();
//		}

		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(grid[i][j] == '.') {
					sb.append(".");
				}
				else {
					int c = 0;
					List<Integer> list = new ArrayList<>();
					for(int k = 0; k < 4; k++) {
						int p = i + dx[k];
						int q = j + dy[k];
						if(p >= 0 && p < n && q >= 0 && q < m && grid[p][q] == '.') {
							if(!list.contains(components[p][q])) {
								list.add(components[p][q]);
								c += cnt[components[p][q]];
							}
						}
					}
					sb.append(((c + 1) % 10)+"");
				}
			}
			sb.append("\n");
		}
		out.print(sb.toString());

		in.close();
		out.flush();
		out.close();
		System.exit(0);
	}

	private static int c = 0;
	private static int ci = 0;
	private static void dfs(int ui, int uj, int n, int m, char[][] grid, boolean[][] visited, int[][] components) {
		c++;
		visited[ui][uj] = true;
		components[ui][uj] = ci;
		for(int i = 0; i < 4; i++) {
			int vi = ui + dx[i];
			int vj = uj + dy[i];
			if(vi >= 0 && vi < n && vj >= 0 && vj < m && grid[vi][vj] == '.' && !visited[vi][vj]) {
				dfs(vi, vj, n, m, grid, visited, components);
			}
		}
	}

	private static class Pair{
		int ci;
		int c;
		public Pair(){
			ci = 0;
			c = 0;
		}
	}

	/*
	 * return the number of elements in list that are less than or equal to the val
	 */
	private static long upperBound(List<Long> list, long val) {
		int start = 0;
		int len = list.size();
		int end = len - 1;
		int mid = 0;

		while (true) {
			if (start > end) {
				break;
			}
			mid = (start + end) / 2;
			long v = list.get(mid);
			if (v == val) {
				start = mid;
				while(start < end) {
					mid = (start + end) / 2;
					if(list.get(mid) == val) {
						if(mid + 1 < len && list.get(mid + 1) == val) {
							start = mid + 1;
						}
						else {
							return mid + 1;
						}
					}
					else {
						end = mid - 1;
					}
				}
				return start + 1;
			}
			if (v > val) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
		}
		if (list.get(mid) < val) {
			return mid + 1;
		}
		return mid;
	}

	private static boolean isPalindrome(String str) {
		StringBuilder sb = new StringBuilder();
		sb.append(str);
		String str1 = sb.reverse().toString();
		return str.equals(str1);
	}

	private static String getBinaryStr(long n, int j) {
		String str = Long.toBinaryString(n);
		int k = str.length();
		for (int i = 1; i <= j - k; i++) {
			str = "0" + str;
		}

		return str;
	}

	private static long modInverse(long r) {
		return bigMod(r, MOD - 2, MOD);
	}

	private static long bigMod(long n, long k, long m) {

        long ans = 1;
        while (k > 0) {
            if ((k & 1) == 1) {
                ans = (ans * n) % m;
            }
            n = (n * n) % m;
            k >>= 1;
        }
        return ans;
    }

	private static long ceil(long n, long x) {
		long div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
	}

    private static int ceil(int n, int x) {
        int div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
    }

    private static int abs(int x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static double abs(double x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static long abs(long x) {
        if(x < 0) {
            return -x;
        }
        return x;
    }

    private static int lcm(int a, int b) {
        return (a * b) / gcd(a, b);
    }

    private static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static long gcd(long a, long b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static int log(long x, int base) {
        return (int) (Math.log(x) / Math.log(base));
    }

    private static long min(long a, long b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static int min(int a, int b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static long max(long a, long b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static int max(int a, int b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());

                }
            } catch (IOException e) {
                return null;
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = null;
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public boolean hasNext() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (Exception e) {
                return false;
            }
            return true;
        }

        public int[] nextIntArr(int n) {
        	int arr[] = new int[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr(int n) {
        	long arr[] = new long[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public int[] nextIntArr1(int n) {
        	int arr[] = new int[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr1(int n) {
        	long arr[] = new long[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public void close() {
        	try {
        		if(reader != null) {
        			reader.close();
        		}
        	}
        	catch(Exception e) {

        	}

        }
    }

}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

    static int n;
    static int m;
    static int[][] matrix;
    static int component;
    static ArrayList<Integer> sizes;
    static int size;
    static int sum = 0;
    static Set<Integer> adj = new HashSet<>();
    static Visitor finalVisitor = (ni, nj) -> {
        int comp = matrix[ni][nj];
        if (comp > 0 && !adj.contains(comp)) {
            adj.add(comp);
            sum += sizes.get(comp);
        }
    };

    public static void solve() {
        n = IO.readInt();
        m = IO.readInt();
        matrix = new int[n][m];
        IO.readLine();
        for (int i = 0; i < n; ++i) {
            String row = IO.readLine();
            for (int j = 0; j < m; ++j) {
                matrix[i][j] = row.charAt(j) == '.' ? 0 : -1;
            }
        }

        markComponents();

        StringBuilder answer = new StringBuilder();
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (matrix[i][j] == -1) {
                    sum = 0;
                    adj.clear();
                    iterate(i, j, finalVisitor);
                    answer.append((sum + 1) % 10);
                    //answer.append('*');
                }
                else {
                    answer.append('.');
                    //answer.append(sizes.get(matrix[i][j]));
                    //answer.append(matrix[i][j]);
                }
            }
            answer.append('\n');
        }
        IO.println(answer);
    }

    static void iterate(int i, int j, Visitor visitor) {
        if (i > 0) {
            visitor.visit(i - 1, j);
        }
        if (j > 0) {
            visitor.visit(i, j - 1);
        }
        if (i < n - 1) {
            visitor.visit(i + 1, j);
        }
        if (j < m - 1) {
            visitor.visit(i, j + 1);
        }
    }

    interface Visitor {
        void visit(int ni, int nj);
    }

    static void markComponents() {
        component = 0;
        sizes = new ArrayList<>();
        sizes.add(0);

        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (matrix[i][j] == 0) {
                    component++;
                    size = 0;
                    dfs(i, j);
                    sizes.add(size);
                }
            }
        }
    }

    static void dfs(int i, int j) {
        matrix[i][j] = component;
        size = 1;
        Deque<Pair<Integer, Integer>> stack = new LinkedList<>();
        stack.addFirst(new Pair<>(i, j));
        Visitor visitor = (ni, nj) -> {
            if (matrix[ni][nj] == 0) {
                stack.addFirst(new Pair<>(ni, nj));
                matrix[ni][nj] = component;
                size++;
            }
        };
        while (!stack.isEmpty()) {
            Pair<Integer, Integer> top = stack.removeFirst();
            iterate(top.key, top.value, visitor);
        }
    }

    // Input/Output ================================
    public static class IO {

        private static Scanner scanner;
        private static PrintWriter writer;

        public static void setUp(InputStream in, OutputStream out) {
            scanner = new Scanner(new java.io.BufferedInputStream(in));
            writer = new PrintWriter(out);
        }

        public static boolean isEmpty() {
            return !scanner.hasNext();
        }

        public static boolean hasNextLine() {
            return scanner.hasNextLine();
        }

        public static String readLine() {
            String line;
            try {
                line = scanner.nextLine();
            }
            catch (Exception e) {
                line = null;
            }
            return line;
        }

        public static String readString() {
            return scanner.next();
        }

        public static int readInt() {
            return scanner.nextInt();
        }

        public static int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int index = 0; index < n; ++index) {
                a[index] = readInt();
            }
            return a;
        }

        public static Pair<Integer, Integer>[] readIntArrayWithIndexes(int n) {
            Pair<Integer, Integer>[] a = new Pair[n];
            for (int index = 0; index < n; ++index) {
                a[index] = new Pair<>(index, readInt());
            }
            return a;
        }

        public static double readDouble() {
            return scanner.nextDouble();
        }

        public static float readFloat() {
            return scanner.nextFloat();
        }

        public static long readLong() {
            return scanner.nextLong();
        }

        public static char readChar() {
            return scanner.findInLine("[^\\s]").charAt(0);
        }

        public static void print(Object o) {
            writer.print(o);
            writer.flush();
        }

        public static void println(Object o) {
            writer.println(o);
            writer.flush();
        }
    }

    // Algorithms ================================

    private static class Algo {

        private static int binSearch(int[] array, int n, int lo, int hi) {
            if (lo > hi) {
                return lo;
            }

            int mid = lo + (hi - lo) / 2;
            int cmp = (int) java.lang.Math.signum(n - array[mid]);
            if (cmp < 0) {
                return binSearch(array, n, lo, mid - 1);
            }
            else if (cmp == 0) {
                return mid;
            }
            else {
                return binSearch(array, n, mid + 1, hi);
            }
        }

        private static void permutations(int n) {
            int[] p = new int[n];
            for (int index = 0; index < n; ++index) {
                p[index] = index + 1;
            }

            while (true) {
                IO.println(Arrays.toString(p));

                int k = n - 1;
                while (k > 0) {
                    if (p[k] < p[k - 1]) {
                        k--;
                    }
                    else {
                        break;
                    }
                }
                if (k == 0) {
                    break;
                }
                int j = n - 1;
                while (p[j] < p[k - 1]) {
                    j--;
                }

                int t = p[j];
                p[j] = p[k - 1];
                p[k - 1] = t;

                int i = 0;
                while (k + i < n - 1 - i) {
                    t = p[k + i];
                    p[k + i] = p[n - i - 1];
                    p[n - i - 1] = t;
                    i++;
                }
            }
        }

        private static boolean isPrime(int number) {
            if (number <= 1) {
                return false;
            }
            if (number <= 3) {
                return true;
            }
            if (number % 2 == 0 || number % 3 == 0) {
                return false;
            }
            int i = 5;
            while (i * i <= number) {
                if (number % i == 0 || number % (i + 2) == 0) {
                    return false;
                }
                i += 6;
            }
            return true;
        }

        private static boolean isPrimeOrOne(int number) {
            return number == 1 || isPrime(number);
        }

        private static boolean isPalindrome(int number) {
            int n = number;
            int reverse = 0;
            while (n > 0) {
                reverse *= 10;
                reverse += (n % 10);
                n /= 10;
            }
            return reverse == number;
        }

        public static int gcd(int a, int b) {
            while (b != 0) {
                int tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }
    }

    private static class Math2 {

        static long c(int n, int k) {
            if (n == 0 && k == 0) {
                return 1;
            }
            int d = 1000;
            int l = 1000000007;
            long[][] c = new long[d + 1][d + 1];
            for (int i = 1; i <= d; ++i) {
                for (int j = 0; j <= i; ++j) {
                    if (i == j || j == 0) {
                        c[i][j] = 1;
                    }
                    else {
                        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % l;
                    }
                }
            }
            return c[n][k];
        }
    }

    static class Pair<K, V> {
        K key;
        V value;

        Pair(K key, V value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        IO.setUp(System.in, System.out);
        /*
        try {
            IO.setUp(new FileInputStream("encode.in"), new FileOutputStream("encode.out"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        */
        solve();
    }
}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

import javafx.util.Pair;

public class Main {

    static int n;
    static int m;
    static int[][] matrix;
    static int component;
    static ArrayList<Integer> sizes;
    static int size;
    static Visitor dfsVisitor = (ni, nj) -> {
        if (matrix[ni][nj] == 0) {
            dfs(ni, nj);
        }
    };
    static int sum = 0;
    static Set<Integer> adj = new HashSet<>();
    static Visitor finalVisitor = (ni, nj) -> {
        int comp = matrix[ni][nj];
        if (comp > 0 && !adj.contains(comp)) {
            adj.add(comp);
            sum += sizes.get(comp);
        }
    };

    public static void solve() {
        n = IO.readInt();
        m = IO.readInt();
        matrix = new int[n][m];
        IO.readLine();
        for (int i = 0; i < n; ++i) {
            String row = IO.readLine();
            for (int j = 0; j < m; ++j) {
                matrix[i][j] = row.charAt(j) == '.' ? 0 : -1;
            }
        }

        markComponents();

        StringBuilder answer = new StringBuilder();
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (matrix[i][j] == -1) {
                    sum = 0;
                    adj.clear();
                    iterate(i, j, finalVisitor);
                    answer.append((sum + 1) % 10);
                }
                else {
                    answer.append('.');
                }
            }
            answer.append('\n');
        }
        IO.println(answer);
    }

    static void iterate(int i, int j, Visitor visitor) {
        if (i > 0) {
            visitor.visit(i - 1, j);
        }
        if (j > 0) {
            visitor.visit(i, j - 1);
        }
        if (i < n - 1) {
            visitor.visit(i + 1, j);
        }
        if (j < m - 1) {
            visitor.visit(i, j + 1);
        }
    }

    interface Visitor {
        void visit(int ni, int nj);
    }

    static void markComponents() {
        component = 0;
        sizes = new ArrayList<>();
        sizes.add(0);

        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (matrix[i][j] == 0) {
                    component++;
                    size = 0;
                    dfs(i, j);
                    sizes.add(size);
                }
            }
        }
    }

    static void dfs(int i, int j) {
        matrix[i][j] = component;
        size++;
        iterate(i, j, dfsVisitor);
    }

    // Input/Output ================================
    public static class IO {

        private static Scanner scanner;
        private static PrintWriter writer;

        public static void setUp(InputStream in, OutputStream out) {
            scanner = new Scanner(new java.io.BufferedInputStream(in));
            writer = new PrintWriter(out);
        }

        public static boolean isEmpty() {
            return !scanner.hasNext();
        }

        public static boolean hasNextLine() {
            return scanner.hasNextLine();
        }

        public static String readLine() {
            String line;
            try {
                line = scanner.nextLine();
            }
            catch (Exception e) {
                line = null;
            }
            return line;
        }

        public static String readString() {
            return scanner.next();
        }

        public static int readInt() {
            return scanner.nextInt();
        }

        public static int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int index = 0; index < n; ++index) {
                a[index] = readInt();
            }
            return a;
        }

        public static Pair<Integer, Integer>[] readIntArrayWithIndexes(int n) {
            Pair<Integer, Integer>[] a = new Pair[n];
            for (int index = 0; index < n; ++index) {
                a[index] = new Pair<>(index, readInt());
            }
            return a;
        }

        public static double readDouble() {
            return scanner.nextDouble();
        }

        public static float readFloat() {
            return scanner.nextFloat();
        }

        public static long readLong() {
            return scanner.nextLong();
        }

        public static char readChar() {
            return scanner.findInLine("[^\\s]").charAt(0);
        }

        public static void print(Object o) {
            writer.print(o);
            writer.flush();
        }

        public static void println(Object o) {
            writer.println(o);
            writer.flush();
        }
    }

    // Algorithms ================================

    private static class Algo {

        private static int binSearch(int[] array, int n, int lo, int hi) {
            if (lo > hi) {
                return lo;
            }

            int mid = lo + (hi - lo) / 2;
            int cmp = (int) java.lang.Math.signum(n - array[mid]);
            if (cmp < 0) {
                return binSearch(array, n, lo, mid - 1);
            }
            else if (cmp == 0) {
                return mid;
            }
            else {
                return binSearch(array, n, mid + 1, hi);
            }
        }

        private static void permutations(int n) {
            int[] p = new int[n];
            for (int index = 0; index < n; ++index) {
                p[index] = index + 1;
            }

            while (true) {
                IO.println(Arrays.toString(p));

                int k = n - 1;
                while (k > 0) {
                    if (p[k] < p[k - 1]) {
                        k--;
                    }
                    else {
                        break;
                    }
                }
                if (k == 0) {
                    break;
                }
                int j = n - 1;
                while (p[j] < p[k - 1]) {
                    j--;
                }

                int t = p[j];
                p[j] = p[k - 1];
                p[k - 1] = t;

                int i = 0;
                while (k + i < n - 1 - i) {
                    t = p[k + i];
                    p[k + i] = p[n - i - 1];
                    p[n - i - 1] = t;
                    i++;
                }
            }
        }

        private static boolean isPrime(int number) {
            if (number <= 1) {
                return false;
            }
            if (number <= 3) {
                return true;
            }
            if (number % 2 == 0 || number % 3 == 0) {
                return false;
            }
            int i = 5;
            while (i * i <= number) {
                if (number % i == 0 || number % (i + 2) == 0) {
                    return false;
                }
                i += 6;
            }
            return true;
        }

        private static boolean isPrimeOrOne(int number) {
            return number == 1 || isPrime(number);
        }

        private static boolean isPalindrome(int number) {
            int n = number;
            int reverse = 0;
            while (n > 0) {
                reverse *= 10;
                reverse += (n % 10);
                n /= 10;
            }
            return reverse == number;
        }

        public static int gcd(int a, int b) {
            while (b != 0) {
                int tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }
    }

    private static class Math2 {

        static long c(int n, int k) {
            if (n == 0 && k == 0) {
                return 1;
            }
            int d = 1000;
            int l = 1000000007;
            long[][] c = new long[d + 1][d + 1];
            for (int i = 1; i <= d; ++i) {
                for (int j = 0; j <= i; ++j) {
                    if (i == j || j == 0) {
                        c[i][j] = 1;
                    }
                    else {
                        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % l;
                    }
                }
            }
            return c[n][k];
        }
    }

    static class Pair<K, V> {
        K key;
        V value;

        Pair(K key, V value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        IO.setUp(System.in, System.out);
        /*
        try {
            IO.setUp(new FileInputStream("encode.in"), new FileOutputStream("encode.out"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        */
        solve();
    }
}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

import javafx.util.Pair;

public class Main {

    static int n;
    static int m;
    static int[][] matrix;
    static int component;
    static ArrayList<Integer> sizes;
    static int size;

    public static void solve() {
        n = IO.readInt();
        m = IO.readInt();
        matrix = new int[n][m];
        IO.readLine();
        for (int i = 0; i < n; ++i) {
            String row = IO.readLine();
            for (int j = 0; j < m; ++j){
                matrix[i][j] = row.charAt(j) == '.' ? 0 : -1;
            }
        }

        markComponents();

        Set<Integer> adj = new HashSet<>();
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j){
                if (matrix[i][j] == -1) {
                    int sum = 0;
                    for (int di = -1; di <= 1; ++di) {
                        for  (int dj = -1; dj <= 1; ++dj) {
                            if (Math.abs(di + dj) != 1) {
                                continue;
                            }

                            if (i + di >= 0 && i + di < n && j + dj >= 0 && j + dj < m) {
                                int comp = matrix[i + di][j + dj];
                                if (comp > 0 && !adj.contains(comp)) {
                                    adj.add(comp);
                                    sum += sizes.get(comp);
                                }
                            }
                        }
                    }

                    adj.clear();
                    IO.print(sum + 1);
                }
                else {
                    IO.print('.');
                }
            }
            IO.println("");
        }
    }

    static void markComponents() {
        component = 0;
        sizes = new ArrayList<>();
        sizes.add(0);

        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j){
                if (matrix[i][j] == 0) {
                    component++;
                    size = 0;
                    dfs(i, j);
                    sizes.add(size);
                }
            }
        }
    }

    static void dfs(int i, int j) {
        matrix[i][j] = component;
        size++;

        for (int di = -1; di <= 1; ++di) {
            for  (int dj = -1; dj <= 1; ++dj) {
                if (Math.abs(di + dj) != 1) {
                    continue;
                }

                if (i + di >= 0 && i + di < n && j + dj >= 0 && j + dj < m) {
                    if (matrix[i + di][j + dj] == 0) {
                        dfs(i + di, j + dj);
                    }
                }
            }
        }
    }

    // Input/Output ================================
    public static class IO {

        private static Scanner scanner;
        private static PrintWriter writer;

        public static void setUp(InputStream in, OutputStream out) {
            scanner = new Scanner(new java.io.BufferedInputStream(in));
            writer = new PrintWriter(out);
        }

        public static boolean isEmpty() {
            return !scanner.hasNext();
        }

        public static boolean hasNextLine() {
            return scanner.hasNextLine();
        }

        public static String readLine() {
            String line;
            try {
                line = scanner.nextLine();
            }
            catch (Exception e) {
                line = null;
            }
            return line;
        }

        public static String readString() {
            return scanner.next();
        }

        public static int readInt() {
            return scanner.nextInt();
        }

        public static int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int index = 0; index < n; ++index) {
                a[index] = readInt();
            }
            return a;
        }

        public static Pair<Integer, Integer>[] readIntArrayWithIndexes(int n) {
            Pair<Integer, Integer>[] a = new Pair[n];
            for (int index = 0; index < n; ++index) {
                a[index] = new Pair<>(index, readInt());
            }
            return a;
        }

        public static double readDouble() {
            return scanner.nextDouble();
        }

        public static float readFloat() {
            return scanner.nextFloat();
        }

        public static long readLong() {
            return scanner.nextLong();
        }

        public static char readChar() {
            return scanner.findInLine("[^\\s]").charAt(0);
        }

        public static void print(Object o) {
            writer.print(o);
            writer.flush();
        }

        public static void println(Object o) {
            writer.println(o);
            writer.flush();
        }
    }

    // Algorithms ================================

    private static class Algo {

        private static int binSearch(int[] array, int n, int lo, int hi) {
            if (lo > hi) {
                return lo;
            }

            int mid = lo + (hi - lo) / 2;
            int cmp = (int) java.lang.Math.signum(n - array[mid]);
            if (cmp < 0) {
                return binSearch(array, n, lo, mid - 1);
            }
            else if (cmp == 0) {
                return mid;
            }
            else {
                return binSearch(array, n, mid + 1, hi);
            }
        }

        private static void permutations(int n) {
            int[] p = new int[n];
            for (int index = 0; index < n; ++index) {
                p[index] = index + 1;
            }

            while (true) {
                IO.println(Arrays.toString(p));

                int k = n - 1;
                while (k > 0) {
                    if (p[k] < p[k - 1]) {
                        k--;
                    }
                    else {
                        break;
                    }
                }
                if (k == 0) {
                    break;
                }
                int j = n - 1;
                while (p[j] < p[k - 1]) {
                    j--;
                }

                int t = p[j];
                p[j] = p[k - 1];
                p[k - 1] = t;

                int i = 0;
                while (k + i < n - 1 - i) {
                    t = p[k + i];
                    p[k + i] = p[n - i - 1];
                    p[n - i - 1] = t;
                    i++;
                }
            }
        }

        private static boolean isPrime(int number) {
            if (number <= 1) {
                return false;
            }
            if (number <= 3) {
                return true;
            }
            if (number % 2 == 0 || number % 3 == 0) {
                return false;
            }
            int i = 5;
            while (i * i <= number) {
                if (number % i == 0 || number % (i + 2) == 0) {
                    return false;
                }
                i += 6;
            }
            return true;
        }

        private static boolean isPrimeOrOne(int number) {
            return number == 1 || isPrime(number);
        }

        private static boolean isPalindrome(int number) {
            int n = number;
            int reverse = 0;
            while (n > 0) {
                reverse *= 10;
                reverse += (n % 10);
                n /= 10;
            }
            return reverse == number;
        }

        public static int gcd(int a, int b) {
            while (b != 0) {
                int tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }
    }

    private static class Math2 {

        static long c(int n, int k) {
            if (n == 0 && k == 0) {
                return 1;
            }
            int d = 1000;
            int l = 1000000007;
            long[][] c = new long[d + 1][d + 1];
            for (int i = 1; i <= d; ++i) {
                for (int j = 0; j <= i; ++j) {
                    if (i == j || j == 0) {
                        c[i][j] = 1;
                    }
                    else {
                        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % l;
                    }
                }
            }
            return c[n][k];
        }
    }

    static class Pair<K, V> {
        K key;
        V value;

        Pair(K key, V value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        IO.setUp(System.in, System.out);
        /*
        try {
            IO.setUp(new FileInputStream("encode.in"), new FileOutputStream("encode.out"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        */
        solve();
    }
}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

import javafx.util.Pair;

public class Main {

    static int n;
    static int m;
    static int[][] matrix;
    static int component;
    static ArrayList<Integer> sizes;
    static int size;

    public static void solve() {
        n = IO.readInt();
        m = IO.readInt();
        matrix = new int[n][m];
        IO.readLine();
        for (int i = 0; i < n; ++i) {
            String row = IO.readLine();
            for (int j = 0; j < m; ++j){
                matrix[i][j] = row.charAt(j) == '.' ? 0 : -1;
            }
        }

        markComponents();

        Set<Integer> adj = new HashSet<>();
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j){
                if (matrix[i][j] == -1) {
                    int sum = 0;
                    for (int di = -1; di <= 1; ++di) {
                        for  (int dj = -1; dj <= 1; ++dj) {
                            if (Math.abs(di + dj) != 1) {
                                continue;
                            }

                            if (i + di >= 0 && i + di < n && j + dj >= 0 && j + dj < m) {
                                int comp = matrix[i + di][j + dj];
                                if (comp > 0 && !adj.contains(comp)) {
                                    adj.add(comp);
                                    sum += sizes.get(comp);
                                }
                            }
                        }
                    }

                    adj.clear();
                    IO.print((sum + 1) % 10);
                }
                else {
                    IO.print('.');
                }
            }
            IO.println("");
        }
    }

    static void markComponents() {
        component = 0;
        sizes = new ArrayList<>();
        sizes.add(0);

        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j){
                if (matrix[i][j] == 0) {
                    component++;
                    size = 0;
                    dfs(i, j);
                    sizes.add(size);
                }
            }
        }
    }

    static void dfs(int i, int j) {
        matrix[i][j] = component;
        size++;

        for (int di = -1; di <= 1; ++di) {
            for  (int dj = -1; dj <= 1; ++dj) {
                if (Math.abs(di + dj) != 1) {
                    continue;
                }

                if (i + di >= 0 && i + di < n && j + dj >= 0 && j + dj < m) {
                    if (matrix[i + di][j + dj] == 0) {
                        dfs(i + di, j + dj);
                    }
                }
            }
        }
    }

    // Input/Output ================================
    public static class IO {

        private static Scanner scanner;
        private static PrintWriter writer;

        public static void setUp(InputStream in, OutputStream out) {
            scanner = new Scanner(new java.io.BufferedInputStream(in));
            writer = new PrintWriter(out);
        }

        public static boolean isEmpty() {
            return !scanner.hasNext();
        }

        public static boolean hasNextLine() {
            return scanner.hasNextLine();
        }

        public static String readLine() {
            String line;
            try {
                line = scanner.nextLine();
            }
            catch (Exception e) {
                line = null;
            }
            return line;
        }

        public static String readString() {
            return scanner.next();
        }

        public static int readInt() {
            return scanner.nextInt();
        }

        public static int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int index = 0; index < n; ++index) {
                a[index] = readInt();
            }
            return a;
        }

        public static Pair<Integer, Integer>[] readIntArrayWithIndexes(int n) {
            Pair<Integer, Integer>[] a = new Pair[n];
            for (int index = 0; index < n; ++index) {
                a[index] = new Pair<>(index, readInt());
            }
            return a;
        }

        public static double readDouble() {
            return scanner.nextDouble();
        }

        public static float readFloat() {
            return scanner.nextFloat();
        }

        public static long readLong() {
            return scanner.nextLong();
        }

        public static char readChar() {
            return scanner.findInLine("[^\\s]").charAt(0);
        }

        public static void print(Object o) {
            writer.print(o);
            writer.flush();
        }

        public static void println(Object o) {
            writer.println(o);
            writer.flush();
        }
    }

    // Algorithms ================================

    private static class Algo {

        private static int binSearch(int[] array, int n, int lo, int hi) {
            if (lo > hi) {
                return lo;
            }

            int mid = lo + (hi - lo) / 2;
            int cmp = (int) java.lang.Math.signum(n - array[mid]);
            if (cmp < 0) {
                return binSearch(array, n, lo, mid - 1);
            }
            else if (cmp == 0) {
                return mid;
            }
            else {
                return binSearch(array, n, mid + 1, hi);
            }
        }

        private static void permutations(int n) {
            int[] p = new int[n];
            for (int index = 0; index < n; ++index) {
                p[index] = index + 1;
            }

            while (true) {
                IO.println(Arrays.toString(p));

                int k = n - 1;
                while (k > 0) {
                    if (p[k] < p[k - 1]) {
                        k--;
                    }
                    else {
                        break;
                    }
                }
                if (k == 0) {
                    break;
                }
                int j = n - 1;
                while (p[j] < p[k - 1]) {
                    j--;
                }

                int t = p[j];
                p[j] = p[k - 1];
                p[k - 1] = t;

                int i = 0;
                while (k + i < n - 1 - i) {
                    t = p[k + i];
                    p[k + i] = p[n - i - 1];
                    p[n - i - 1] = t;
                    i++;
                }
            }
        }

        private static boolean isPrime(int number) {
            if (number <= 1) {
                return false;
            }
            if (number <= 3) {
                return true;
            }
            if (number % 2 == 0 || number % 3 == 0) {
                return false;
            }
            int i = 5;
            while (i * i <= number) {
                if (number % i == 0 || number % (i + 2) == 0) {
                    return false;
                }
                i += 6;
            }
            return true;
        }

        private static boolean isPrimeOrOne(int number) {
            return number == 1 || isPrime(number);
        }

        private static boolean isPalindrome(int number) {
            int n = number;
            int reverse = 0;
            while (n > 0) {
                reverse *= 10;
                reverse += (n % 10);
                n /= 10;
            }
            return reverse == number;
        }

        public static int gcd(int a, int b) {
            while (b != 0) {
                int tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }
    }

    private static class Math2 {

        static long c(int n, int k) {
            if (n == 0 && k == 0) {
                return 1;
            }
            int d = 1000;
            int l = 1000000007;
            long[][] c = new long[d + 1][d + 1];
            for (int i = 1; i <= d; ++i) {
                for (int j = 0; j <= i; ++j) {
                    if (i == j || j == 0) {
                        c[i][j] = 1;
                    }
                    else {
                        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % l;
                    }
                }
            }
            return c[n][k];
        }
    }

    static class Pair<K, V> {
        K key;
        V value;

        Pair(K key, V value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        IO.setUp(System.in, System.out);
        /*
        try {
            IO.setUp(new FileInputStream("encode.in"), new FileOutputStream("encode.out"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        */
        solve();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class Task {

	int used[][];
	char arr[][];
	int ids[][];
	int sizes[][];

	int n, m;
	class Point {
		public int x, y;

		public Point(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}
	}

	int usedLevel;

	boolean isOnBoard(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < m;
	}

	boolean valid(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < m && used[x][y] < usedLevel && arr[x][y]=='.';
	}

	int go(int x, int y, int ids[][], int id) {
		int currSize = 0;

		List<Point> s = new ArrayList<Point>();

		s.add(new Point(x, y));
		//used[x][y] = usedLevel;
		//ids[x][y] = id;

		for(int i = 0; i < s.size(); i++) {
			int cx =  s.get(i).x;
			int cy = s.get(i).y;

			ids[cx][cy] = id;

			if(used[cx][cy] == usedLevel) continue;

			used[cx][cy] = usedLevel;
			currSize++;

			if (valid(cx+1, cy)) s.add(new Point(cx+1, cy));
			if (valid(cx-1, cy)) s.add(new Point(cx-1, cy));
			if (valid(cx, cy+1)) s.add(new Point(cx, cy+1));
			if (valid(cx, cy-1)) s.add(new Point(cx, cy-1));
		}

		return currSize;
	}

	public void solve(InputReader in, PrintWriter out)  {

		n = in.nextInt();
		m = in.nextInt();

		arr = new char[n][m];
		used = new int[n][m];
		ids = new int[n][m];
		sizes = new int[n][m];

		for(int i = 0; i < n; i++) {
			String s = in.next();
			arr[i] = s.toCharArray();
		}

		int currId = 1;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(arr[i][j] == '.' && used[i][j]==0) {
					usedLevel = 1;
					int size = go(i, j, ids, currId);
					usedLevel = 2;
					go(i, j, sizes, size);

					currId++;
				}
			}
		}

//		for(int i = 0; i < n; i++) {
//			for(int j = 0; j < m; j++) {
//				System.out.print(ids[i][j]);
//			}
//			System.out.println();
//		}
//		System.out.println();
//		for(int i = 0; i < n; i++) {
//			for(int j = 0; j < m; j++) {
//				System.out.print(sizes[i][j] + "\t");
//			}
//			System.out.println();
//		}

		Set<Integer> idsUsed = new HashSet<>();
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(arr[i][j] == '*') {
					int sum = 1;
					idsUsed.clear();

					if(isOnBoard(i+1, j) && arr[i+1][j]=='.' && !idsUsed.contains(ids[i+1][j])) {
						idsUsed.add(ids[i+1][j]);
						sum += sizes[i+1][j];
					}

					if(isOnBoard(i-1, j) && arr[i-1][j]=='.' && !idsUsed.contains(ids[i-1][j])) {
						idsUsed.add(ids[i-1][j]);
						sum += sizes[i-1][j];
					}

					if(isOnBoard(i, j+1) && arr[i][j+1]=='.' && !idsUsed.contains(ids[i][j+1])) {
						idsUsed.add(ids[i][j+1]);
						sum += sizes[i][j+1];
					}

					if(isOnBoard(i, j-1) && arr[i][j-1]=='.' && !idsUsed.contains(ids[i][j-1])) {
						idsUsed.add(ids[i][j-1]);
						sum += sizes[i][j-1];
					}

					arr[i][j] = (char) ('0' + (sum%10));
				}
			}
		}

//		System.out.println();
		for(int i = 0; i < n; i++) {
			out.println(arr[i]);
		}

	}

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class Task {

    int used[][];
    char arr[][];
    int ids[][];
    int sizes[][];

    int n, m;
    class Point {
        public int x, y;

        public Point(int x, int y) {
            super();
            this.x = x;
            this.y = y;
        }
    }

    int usedLevel;

    boolean isOnBoard(int x, int y) {
        return x >= 0 && x < n && y >= 0 && y < m;
    }

    boolean valid(int x, int y) {
        return x >= 0 && x < n && y >= 0 && y < m && used[x][y] < usedLevel && arr[x][y]=='.';
    }

    int go(int x, int y, int ids[][], int id) {
        int currSize = 0;

        List<Point> s = new ArrayList<Point>();

        s.add(new Point(x, y));
        used[x][y] = usedLevel;
        ids[x][y] = id;

        for(int i = 0; i < s.size(); i++) {
            int cx =  s.get(i).x;
            int cy = s.get(i).y;
            used[cx][cy] = usedLevel;
            ids[cx][cy] = id;

            currSize++;

            if (valid(cx+1, cy)) s.add(new Point(cx+1, cy));
            if (valid(cx-1, cy)) s.add(new Point(cx-1, cy));
            if (valid(cx, cy+1)) s.add(new Point(cx, cy+1));
            if (valid(cx, cy-1)) s.add(new Point(cx, cy-1));
        }

        return currSize;
    }

    public void solve(InputReader in, PrintWriter out)  {

        n = in.nextInt();
        m = in.nextInt();

        arr = new char[n][m];
        used = new int[n][m];
        ids = new int[n][m];
        sizes = new int[n][m];

        for(int i = 0; i < n; i++) {
            String s = in.next();
            arr[i] = s.toCharArray();
        }

        int currId = 1;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if(arr[i][j] == '.' && used[i][j]==0) {
                    usedLevel = 1;
                    int size = go(i, j, ids, currId);
                    usedLevel = 2;
                    go(i, j, sizes, size);

                    currId++;
                }
            }
        }

//      for(int i = 0; i < n; i++) {
//          for(int j = 0; j < m; j++) {
//              System.out.print(ids[i][j]);
//          }
//          System.out.println();
//      }
//      System.out.println();
//      for(int i = 0; i < n; i++) {
//          for(int j = 0; j < m; j++) {
//              System.out.print(sizes[i][j]);
//          }
//          System.out.println();
//      }

        Set<Integer> idsUsed = new HashSet<>();
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if(arr[i][j] == '*') {
                    int sum = 1;
                    idsUsed.clear();

                    if(isOnBoard(i+1, j) && arr[i+1][j]=='.' && !idsUsed.contains(ids[i+1][j])) {
                        idsUsed.add(ids[i+1][j]);
                        sum += sizes[i+1][j];
                    }

                    if(isOnBoard(i-1, j) && arr[i-1][j]=='.' && !idsUsed.contains(ids[i-1][j])) {
                        idsUsed.add(ids[i-1][j]);
                        sum += sizes[i-1][j];
                    }

                    if(isOnBoard(i, j+1) && arr[i][j+1]=='.' && !idsUsed.contains(ids[i][j+1])) {
                        idsUsed.add(ids[i][j+1]);
                        sum += sizes[i][j+1];
                    }

                    if(isOnBoard(i, j-1) && arr[i][j-1]=='.' && !idsUsed.contains(ids[i][j-1])) {
                        idsUsed.add(ids[i][j-1]);
                        sum += sizes[i][j-1];
                    }

                    arr[i][j] = (char) ('0' + (sum%10));
                }
            }
        }

//      System.out.println();
        for(int i = 0; i < n; i++) {
            out.println(arr[i]);
        }

    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class Task {

	int used[][];
	char arr[][];
	int ids[][];
	int sizes[][];

	int n, m;
	class Point {
		public int x, y;

		public Point(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}
	}

	int usedLevel;

	boolean isOnBoard(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < m;
	}

	boolean valid(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < m && used[x][y] < usedLevel && arr[x][y]=='.';
	}

	int go(int x, int y, int ids[][], int id) {
		int currSize = 0;

		List<Point> s = new ArrayList<Point>();

		s.add(new Point(x, y));
		used[x][y] = usedLevel;
		ids[x][y] = id;

		for(int i = 0; i < s.size(); i++) {
			int cx =  s.get(i).x;
			int cy = s.get(i).y;
			used[cx][cy] = usedLevel;
			ids[cx][cy] = id;

			currSize++;

			if (valid(cx+1, cy)) s.add(new Point(cx+1, cy));
			if (valid(cx-1, cy)) s.add(new Point(cx-1, cy));
			if (valid(cx, cy+1)) s.add(new Point(cx, cy+1));
			if (valid(cx, cy-1)) s.add(new Point(cx, cy-1));
		}

		return currSize;
	}

	public void solve(InputReader in, PrintWriter out)  {

		n = in.nextInt();
		m = in.nextInt();

		arr = new char[n][m];
		used = new int[n][m];
		ids = new int[n][m];
		sizes = new int[n][m];

		for(int i = 0; i < n; i++) {
			String s = in.next();
			arr[i] = s.toCharArray();
		}

		int currId = 1;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(arr[i][j] == '.' && used[i][j]==0) {
					usedLevel = 1;
					int size = go(i, j, ids, currId);
					usedLevel = 2;
					go(i, j, sizes, size);

					currId++;
				}
			}
		}

//		for(int i = 0; i < n; i++) {
//			for(int j = 0; j < m; j++) {
//				System.out.print(ids[i][j]);
//			}
//			System.out.println();
//		}
//		System.out.println();
//		for(int i = 0; i < n; i++) {
//			for(int j = 0; j < m; j++) {
//				System.out.print(sizes[i][j]);
//			}
//			System.out.println();
//		}

		Set<Integer> idsUsed = new HashSet<>();
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(arr[i][j] == '*') {
					int sum = 1;
					idsUsed.clear();

					if(isOnBoard(i+1, j) && arr[i+1][j]=='.' && !idsUsed.contains(ids[i+1][j])) {
						idsUsed.add(ids[i+1][j]);
						sum += sizes[i+1][j];
					}

					if(isOnBoard(i-1, j) && arr[i-1][j]=='.' && !idsUsed.contains(ids[i-1][j])) {
						idsUsed.add(ids[i-1][j]);
						sum += sizes[i-1][j];
					}

					if(isOnBoard(i, j+1) && arr[i][j+1]=='.' && !idsUsed.contains(ids[i][j+1])) {
						idsUsed.add(ids[i][j+1]);
						sum += sizes[i][j+1];
					}

					if(isOnBoard(i, j-1) && arr[i][j-1]=='.' && !idsUsed.contains(ids[i][j-1])) {
						idsUsed.add(ids[i][j-1]);
						sum += sizes[i][j-1];
					}

					arr[i][j] = (char) ('0' + (sum%10));
				}
			}
		}

//		System.out.println();
		for(int i = 0; i < n; i++) {
			out.println(arr[i]);
		}

	}

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


     /*
    	     * Author- Priyam Vora
    	     * BTech 2nd Year DAIICT
    	     */

    	    import java.io.*;
    	    import java.math.*;
    	    import java.util.*;
    	    import javax.print.attribute.SetOfIntegerSyntax;

    	    public class Main{
    	    	private static InputStream stream;
    	    	private static byte[] buf = new byte[1024];
    	    	private static int curChar;
    	    	private static int numChars;
    	    	private static SpaceCharFilter filter;
    	    	private static PrintWriter pw;
    	    	private static long count = 0,mod=1000000007;
    	    	private static TreeSet<Integer>ts[]=new TreeSet[200000];
    	    	private static HashSet hs=new HashSet();

    	    	public static void main(String args[]) throws Exception {
    	    		InputReader(System.in);
    	    		pw = new PrintWriter(System.out);
    	    		//ans();
    	    		soln();
    	    		pw.close();
    	    	}

    	    	public static long gcd(long x, long y) {
    	    		if (x == 0)
    	    			return y;
    	    		else
    	    			return gcd( y % x,x);
    	    	}

    	    	private static int BinarySearch(int a[], int low, int high, int target) {
    	    		if (low > high)
    	    			return -1;
    	    		int mid = low + (high - low) / 2;
    	    		if (a[mid] == target)
    	    			return mid;
    	    		if (a[mid] > target)
    	    			high = mid - 1;
    	    		if (a[mid] < target)
    	    			low = mid + 1;
    	    		return BinarySearch(a, low, high, target);
    	    	}

    	    	public static String reverseString(String s) {
    	    		StringBuilder sb = new StringBuilder(s);
    	    		sb.reverse();
    	    		return (sb.toString());
    	    	}

    	    	public static long pow(long n, long p) {
    	    		if(p==0)
    	    			return 1;
    	    		if(p==1)
    	    			return n%mod;
    	    		if(p%2==0){
    	    			long temp=pow(n, p/2);
    	    		return (temp*temp)%mod;
    	    		}else{
    	    			 	long temp=pow(n,p/2);
    	    			 	temp=(temp*temp)%mod;
    	    			 	return(temp*n)%mod;

    	    		}
    	    	}

    	    	public static int[] radixSort(int[] f) {
    	    		int[] to = new int[f.length];
    	    		{
    	    			int[] b = new int[65537];
    	    			for (int i = 0; i < f.length; i++)
    	    				b[1 + (f[i] & 0xffff)]++;
    	    			for (int i = 1; i <= 65536; i++)
    	    				b[i] += b[i - 1];
    	    			for (int i = 0; i < f.length; i++)
    	    				to[b[f[i] & 0xffff]++] = f[i];
    	    			int[] d = f;
    	    			f = to;
    	    			to = d;
    	    		}
    	    		{
    	    			int[] b = new int[65537];
    	    			for (int i = 0; i < f.length; i++)
    	    				b[1 + (f[i] >>> 16)]++;
    	    			for (int i = 1; i <= 65536; i++)
    	    				b[i] += b[i - 1];
    	    			for (int i = 0; i < f.length; i++)
    	    				to[b[f[i] >>> 16]++] = f[i];
    	    			int[] d = f;
    	    			f = to;
    	    			to = d;
    	    		}
    	    		return f;
    	    	}

    	    	public static int nextPowerOf2(final int a) {
    	    		int b = 1;
    	    		while (b < a) {
    	    			b = b << 1;
    	    		}
    	    		return b;
    	    	}

    	    	public static boolean PointInTriangle(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) {
    	    		int s = p2 * p5 - p1 * p6 + (p6 - p2) * p7 + (p1 - p5) * p8;
    	    		int t = p1 * p4 - p2 * p3 + (p2 - p4) * p7 + (p3 - p1) * p8;

    	    		if ((s < 0) != (t < 0))
    	    			return false;

    	    		int A = -p4 * p5 + p2 * (p5 - p3) + p1 * (p4 - p6) + p3 * p6;
    	    		if (A < 0.0) {
    	    			s = -s;
    	    			t = -t;
    	    			A = -A;
    	    		}
    	    		return s > 0 && t > 0 && (s + t) <= A;
    	    	}

    	    	public static float area(int x1, int y1, int x2, int y2, int x3, int y3) {
    	    		return (float) Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
    	    	}

    	    	public static boolean isPrime(int n) {
    	    		// Corner cases
    	    		if (n <= 1)
    	    			return false;
    	    		if (n <= 3)
    	    			return true;

    	    		// This is checked so that we can skip
    	    		// middle five numbers in below loop
    	    		if (n % 2 == 0 || n % 3 == 0)
    	    			return false;

    	    		for (int i = 5; i * i <= n; i = i + 6)
    	    			if (n % i == 0 || n % (i + 2) == 0)
    	    				return false;

    	    		return true;
    	    	}

    	    	//merge Sort

    	    	static long sort(int a[])
    	    	{  int n=a.length;
    	    		int b[]=new int[n];
    	    		return mergeSort(a,b,0,n-1);}
    	    	static long mergeSort(int a[],int b[],long left,long right)
    	    	{ long c=0;if(left<right)
    	    	 {   long mid=left+(right-left)/2;
    	    		 c= mergeSort(a,b,left,mid);
    	    		 c+=mergeSort(a,b,mid+1,right);
    	    		 c+=merge(a,b,left,mid+1,right); }
    	    		return c;	 }
    	    	static long merge(int a[],int  b[],long left,long mid,long right)
    	    	{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
    	    	while(i<=(int)mid-1&&j<=(int)right)
    	    	{ if(a[i]>a[j]) {b[k++]=a[i++]; }
    	    	else	{ b[k++]=a[j++];c+=mid-i;}}
    	    	while (i <= (int)mid - 1)   b[k++] = a[i++];
    	    	while (j <= (int)right) b[k++] = a[j++];
    	    	for (i=(int)left; i <= (int)right; i++)
    	    		a[i] = b[i];  return c;  }
    	    	public static boolean isSubSequence(String large, String small, int largeLen, int smallLen) {
    	    		//base cases
    	    		if (largeLen == 0)
    	    			return false;
    	    		if (smallLen == 0)
    	    			return true;
    	    		// If last characters of two strings are matching
    	    		if (large.charAt(largeLen - 1) == small.charAt(smallLen - 1))
    	    			isSubSequence(large, small, largeLen - 1, smallLen - 1);
    	    		// If last characters are not matching
    	    		return isSubSequence(large, small, largeLen - 1, smallLen);
    	    	}

    	    	// To Get Input
    	    	// Some Buffer Methods

    	    	public static void InputReader(InputStream stream1) {
    	    		stream = stream1;
    	    	}

    	    	private static boolean isWhitespace(int c) {
    	    		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    	    	}

    	    	private static boolean isEndOfLine(int c) {
    	    		return c == '\n' || c == '\r' || c == -1;
    	    	}

    	    	private static int read() {
    	    		if (numChars == -1)
    	    			throw new InputMismatchException();
    	    		if (curChar >= numChars) {
    	    			curChar = 0;
    	    			try {
    	    				numChars = stream.read(buf);
    	    			} catch (IOException e) {
    	    				throw new InputMismatchException();
    	    			}
    	    			if (numChars <= 0)
    	    				return -1;
    	    		}
    	    		return buf[curChar++];
    	    	}

    	    	private static int nextInt() {
    	    		int c = read();
    	    		while (isSpaceChar(c))
    	    			c = read();
    	    		int sgn = 1;
    	    		if (c == '-') {
    	    			sgn = -1;
    	    			c = read();
    	    		}
    	    		int res = 0;
    	    		do {
    	    			if (c < '0' || c > '9')
    	    				throw new InputMismatchException();
    	    			res *= 10;
    	    			res += c - '0';
    	    			c = read();
    	    		} while (!isSpaceChar(c));
    	    		return res * sgn;
    	    	}

    	    	private static long nextLong() {
    	    		int c = read();
    	    		while (isSpaceChar(c))
    	    			c = read();
    	    		int sgn = 1;
    	    		if (c == '-') {
    	    			sgn = -1;
    	    			c = read();
    	    		}
    	    		long res = 0;
    	    		do {
    	    			if (c < '0' || c > '9')
    	    				throw new InputMismatchException();
    	    			res *= 10;
    	    			res += c - '0';
    	    			c = read();
    	    		} while (!isSpaceChar(c));
    	    		return res * sgn;
    	    	}

    	    	private static String nextToken() {
    	    		int c = read();
    	    		while (isSpaceChar(c))
    	    			c = read();
    	    		StringBuilder res = new StringBuilder();
    	    		do {
    	    			res.appendCodePoint(c);
    	    			c = read();
    	    		} while (!isSpaceChar(c));
    	    		return res.toString();
    	    	}

    	    	private static String nextLine() {
    	    		int c = read();
    	    		while (isSpaceChar(c))
    	    			c = read();
    	    		StringBuilder res = new StringBuilder();
    	    		do {
    	    			res.appendCodePoint(c);
    	    			c = read();
    	    		} while (!isEndOfLine(c));
    	    		return res.toString();
    	    	}

    	    	private static int[] nextIntArray(int n) {
    	    		int[] arr = new int[n];
    	    		for (int i = 0; i < n; i++) {
    	    			arr[i] = nextInt();
    	    		}
    	    		return arr;
    	    	}

    	    	private static int[][] next2dArray(int n, int m) {
    	    		int[][] arr = new int[n][m];
    	    		for (int i = 0; i < n; i++) {
    	    			for (int j = 0; j < m; j++) {
    	    				arr[i][j] = nextInt();
    	    			}
    	    		}
    	    		return arr;
    	    	}
    	    	private static char[][] nextCharArray(int n,int m){
    	    		char [][]c=new char[n][m];
    	    		for(int i=0;i<n;i++){
    	    			String s=nextLine();
    	    			c[i]=s.toCharArray();
    	    		}
    	    		return c;
    	    	}

    	    	private static long[] nextLongArray(int n) {
    	    		long[] arr = new long[n];
    	    		for (int i = 0; i < n; i++) {
    	    			arr[i] = nextLong();
    	    		}
    	    		return arr;
    	    	}

    	    	private static void pArray(int[] arr) {
    	    		for (int i = 0; i < arr.length; i++) {
    	    			pw.print(arr[i] + " ");
    	    		}
    	    		pw.println();
    	    		return;
    	    	}

    	    	private static void pArray(long[] arr) {
    	    		for (int i = 0; i < arr.length; i++) {
    	    			pw.print(arr[i] + " ");
    	    		}
    	    		pw.println();
    	    		return;
    	    	}

    	    	private static void pArray(boolean[] arr) {
    	    		for (int i = 0; i < arr.length; i++) {
    	    			pw.print(arr[i] + " ");
    	    		}
    	    		pw.println();
    	    		return;
    	    	}

    	    	private static boolean isSpaceChar(int c) {
    	    		if (filter != null)
    	    			return filter.isSpaceChar(c);
    	    		return isWhitespace(c);
    	    	}

    	    	private interface SpaceCharFilter {
    	    		public boolean isSpaceChar(int ch);
    	    	}

    	    	//----------------------------------------My Code------------------------------------------------//

    	    	private static void soln() {

    	    		int n=nextInt();
    	    		int m=nextInt();
    	    		char c[][]=nextCharArray(n, m);
    	    		Graph g=new Graph(n);
    	    		StringBuilder sb=new StringBuilder();
    	    		for(int i=0;i<n;i++){
    	    			for(int j=0;j<m;j++){
    	    				if(c[i][j]=='*'){
    	    					sb.append(g.BFS(i, j, c));
    	    					//break;
    	    				}else{
    	    					sb.append(".");
    	    				}
    	    			}
    sb.append("\n");
    	    		}
    	    		pw.println(sb);

    	    	}
    	    		//-----------------------------------------The End--------------------------------------------------------------------------//

    	    }

    		class Pair implements Comparable<Pair>{

    			int idx,val;
    			Pair(int idx,int val){
    				this.idx=idx;
    				this.val=val;
    			}
    			@Override
    			public int compareTo(Pair o) {
    				// TODO Auto-generated method stub
    			//	Sort in increasing order

    				if(o.idx<idx){
    					return 1;
    				}
    				if(o.idx==idx && o.val<val){
    					return 1;
    				}else{
    					return -1;
    				}

    			}

    		}
    	        class Graph{
    	        	private int V,level[][],count=-1,lev_dfs[],degree=0;
    	        	private Stack <Integer>st=new Stack();
    	        	private LinkedList<Integer > adj[];
    	        	private boolean[][] Visite;
    	        	private boolean [] Visited;
    	    Graph(int V){
    	    V++;
    	    this.V=(V);
    	    adj=new LinkedList[V];
    	    Visite=new boolean[1000][1000];
    	    Visited=new boolean[V];
    	    level=new int[100][100];
    	   lev_dfs=new int[V];
    	   for(int i=0;i<V;i++)
    		   adj[i]=new LinkedList<Integer>();
    	    }

    	    void addEdge(int v,int w){

    	    	if(adj[v]==null){
    	    		adj[v]=new LinkedList();
    	    	}
    	    	adj[v].add(w);

    	    }

    	    public int getEd(){
    	    	return degree/2;
    	    }

    	    private static boolean check(int x,int y,char c[][]){

    			if((x>=0 && y>=0) && (x<c.length && y<c[0].length) && c[x][y]=='.'){

    				return true;
    			}
    			return false;
    		}
    	    public long BFS(int x,int y,char[][] c)
    	    {
    	    	 LinkedList<Pair> queue = new LinkedList<Pair>();
    	        //Visited[s]=true;
    	        queue.add(new Pair(x,y));
    	       long count=0;
    	   level[x][y]=-1;
    	  Visite=new boolean[1000][1000];
    	        while (!queue.isEmpty())
    	        {
    	            Pair temp = queue.poll();
    	            x=temp.idx;
    	            y=temp.val;
    	            count++;

    	       //System.out.println(x+" "+y+" ---"+count);

    	         // System.out.println(x+" "+y);
    	           // V--;
    	           if(check(x+1, y, c) && !Visite[x+1][y]){
    	        	queue.add(new Pair(x+1,y));
    	        	Visite[x+1][y]=true;
    	           }
    	           if(check(x-1, y, c) && !Visite[x-1][y]){
    		        	queue.add(new Pair(x-1,y));
    		        	Visite[x-1][y]=true;
    		           }
    	           if(check(x, y+1, c) && !Visite[x][y+1]){
    		        	queue.add(new Pair(x,y+1));
    		        	Visite[x][y+1]=true;
    		           }
    	           if(check(x, y-1, c) && !Visite[x][y-1]){
    		        	queue.add(new Pair(x,y-1));
    		        	Visite[x][y-1]=true;
    		           }
    	        }
    	        count%=10;

    	        return count;
    	    }

    	     public long dfs(int startVertex){

    	     if(!Visited[startVertex])  {

    	    		  return dfsUtil(startVertex,Visited);

    	    }

    	    return -1;
    	    	 }
    	    private long dfsUtil(int startVertex, boolean[] Visited) {//0-Blue 1-Pink
    	      long c=1;
    	      degree=0;
    	    	Visited[startVertex]=true;
    	    	lev_dfs[startVertex]=0;
    	      st.push(startVertex);
    	    while(!st.isEmpty()){
    	    	int top=st.pop();

    	    	Iterator<Integer> i=adj[top].listIterator();
    	     degree+=adj[top].size();
    	    while(i.hasNext()){
    	    //	System.out.println(top);
    	    	int n=i.next();
    	    		 if( !Visited[n]){
    	    				Visited[n]=true;
    	    					st.push(n);
    	    					c++;

    	    		 }
    	    			 }

    	    	}

    	    return c;
    	    	}

    	    }

    	    class Dsu{
    	    	private int rank[], parent[] ,n;

    	    	Dsu(int size){
    	    		this.n=size+1;
    	    		rank=new int[n];
    	    		parent=new int[n];
    	    	makeSet();
    	    	}

    	    	void makeSet(){
    	    		for(int i=0;i<n;i++){
    	    			parent[i]=i;
    	    		}
    	    	}

    	    	int find(int x){
    	    		if(parent[x]!=x){

    	    			parent[x]=find(parent[x]);
    	    		}
    	    		return parent[x];
    	    	}

    	    	void union(int x,int y){
    	    		int xRoot=find(x);
    	    		int yRoot=find(y);

    	    		if(xRoot==yRoot)
    	    			return;
    	    		if(rank[xRoot]<rank[yRoot]){
    	    		parent[xRoot]=yRoot;
    	    		}else if(rank[yRoot]<rank[xRoot]){
    	    			parent[yRoot]=xRoot;
    	    		}else{
    	    			parent[yRoot]=xRoot;
    	    			rank[xRoot]++;
    	    		}

    	    	}

    	    }
    	    class Heap{

    	    	public static void build_max_heap(long []a,int size){

    	    		for(int i=size/2;i>0;i--){
    	    			max_heapify(a, i,size);
    	    		}

    	    			}
    	    	private static void max_heapify(long[] a,int i,int size){
    	    		int left_child=2*i;
    	    		int right_child=(2*i+1);
    	    		int largest=0;

    	    		if(left_child<size && a[left_child]>a[i]){
    	    			largest=left_child;
    	    		}else{
    	    			largest=i;
    	    		}

    	    		if(right_child<size && a[right_child]>a[largest]){
    	    			largest=right_child;
    	    		}
    	    		if(largest!=i){
    	    			long temp=a[largest];
    	    			a[largest]=a[i];
    	    			a[i]=temp;
    	    			max_heapify(a, largest,size);
    	    		}
    	    	}
    	    	private static void min_heapify(int[] a,int i){
    	    		int left_child=2*i;
    	    		int right_child=(2*i+1);
    	    		int largest=0;

    	    		if(left_child<a.length && a[left_child]<a[i]){
    	    			largest=left_child;
    	    		}else{
    	    			largest=i;
    	    		}

    	    		if(right_child<a.length && a[right_child]<a[largest]){
    	    			largest=right_child;
    	    		}
    	    		if(largest!=i){
    	    			int temp=a[largest];
    	    			a[largest]=a[i];
    	    			a[i]=temp;
    	    			min_heapify(a, largest);
    	    		}
    	    	}
    	    	public static void extract_max(int size,long a[]){
    	    		if(a.length>1){
    	    			long max=a[1];
    	    			a[1]=a[a.length-1];
    	    			size--;
    	    			max_heapify(a, 1,a.length-1);
    	    		}
    	    	}
    	    }

    	    class MyComp implements Comparator<Long>{

    			@Override
    			public int compare(Long o1, Long o2) {
    				if(o1<o2){
    					return 1;
    				}else if(o1>o2){
    					return -1;
    				}
    				return 0;

    			}
    	    }


import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
  static int n, m;
  static char[][] s;

  static final int[] dx = new int[]{0, -1, 0, 1}, dy = new int[]{-1, 0, 1, 0};
  static boolean[][] visited1, visited2;
  static int color;
  static int[][] values, colors;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt(); m = sc.nextInt();
    s = new char[n][m];
    for(int i = 0; i < n; i++){
      s[i] = sc.next().toCharArray();
    }

    visited1 = new boolean[n][m]; visited2 = new boolean[n][m];
    values = new int[n][m]; colors = new int[n][m];
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        if(s[i][j] != '*' && !visited1[i][j] && !visited2[i][j]){
          int v = dfs1(j, i);
          dfs2(j, i, v, ++color);
        }
      }
    }

/*
    System.out.println("---");
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        System.out.print(values[i][j]);
      }
      System.out.println();
    }
    System.out.println("---");
    System.out.println("---");
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        System.out.print(colors[i][j]);
      }
      System.out.println();
    }
    System.out.println("---");
*/

    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        if(s[i][j] == '*'){
          int sum = 1;
          Set< Integer > kinds = new TreeSet< Integer >();
          for(int k = 0; k < 4; k++){
            int nx = j + dx[k], ny = i + dy[k];
            if(0 <= nx && nx < m && 0 <= ny && ny < n &&
              !kinds.contains(colors[ny][nx])){
              sum = (sum + values[ny][nx]) % 10;
              kinds.add(colors[ny][nx]);
            }
          }
          s[i][j] = (char)((sum % 10) + '0');
        }
      }
    }

    for(int i = 0; i < n; i++){
      System.out.println(s[i]);
    }
  }

  private static int dfs1(int x, int y){
    if(s[y][x] == '*' || visited1[y][x]){
      return 0;
    }
    visited1[y][x] = true;
    int sum = 0;
    for(int i = 0; i < 4; i++){
      int nx = x + dx[i], ny = y + dy[i];
      if(0 <= nx && nx < m && 0 <= ny && ny < n){
        sum = (sum + dfs1(nx, ny)) % 10;
      }
    }
    return sum + 1;
  }

  private static void dfs2(int x, int y, int v, int color){
    if(s[y][x] == '*' || visited2[y][x]){
      return;
    }
    visited2[y][x] = true;
    colors[y][x] = color; values[y][x] = v;
    for(int i = 0; i < 4; i++){
      int nx = x + dx[i], ny = y + dy[i];
      if(0 <= nx && nx < m && 0 <= ny && ny < n){
        dfs2(nx, ny, v, color);
      }
    }
  }
}