import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;

public class P616C {
    static long mod=1000000007;
    static int s[][];
    static Pair p[][];
    static boolean b[][];
    public static Pair find(int i,int j)
    {
        //Pair x=new Pair(i,j);
        if(p[i][j].a==i&&p[i][j].b==j)
        //if(p[i][j]==x)
            return p[i][j];
        Pair result=find(p[i][j].a,p[i][j].b);
        p[i][j]=result;
        return result;
    }
    public static void union(int x,int y,int x1,int y1)
    {
        Pair xp=find(x,y);
        Pair yp=find(x1,y1);
        if(xp!=yp)
        {
            p[x][y]=yp;
            s[x1][y1]+=s[x][y];

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

            int n=in.readInt();
            int m=in.readInt();
        char c[][]=new char[n][m];
        int a[][]=new int[n][m];
        p=new Pair[n][m];
        s=new int[n][m];
        //b=new boolean[n][m];

        for(int i=0;i<n;i++)
        {
            String x=in.readString();
            c[i]=x.toCharArray();
            for(int j=0;j<m;j++)
            {
                if(c[i][j]=='.')
                {
                    a[i][j]=1;
                    Pair d=new Pair(i,j);
                    p[i][j]=d;
                    s[i][j]=1;
                }

            }
        }

        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(a[i][j]==1)
                {
                    if(i+1<n&&a[i+1][j]==1)
                    {
                         union(i+1,j,i,j);

                    }
                    if(j+1<m&&a[i][j+1]==1)
                    {
                         union(i,j+1,i,j);
                    }
                }
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(a[i][j]==0)
                {
                    int d=0,e=0,f=0,g=0;
                    boolean d1=false;
                    boolean d2,d3,d4;
                    d2=d3=d4=d1;
                    int ans=1;
                    HashSet<Pair>hs=new HashSet<Pair>();
                    if(i+1<n&&a[i+1][j]==1)
                    {
                        Pair x=p[i+1][j];
                        d=s[x.a][x.b];
                         hs.add(x);
                    }
                    if(j+1<m&&a[i][j+1]==1)
                    {
                        Pair x=p[i][j+1];
                        if(!hs.contains(p[i][j+1]))
                        {
                            e=s[x.a][x.b];
                             hs.add(x);
                        }
                    }
                    if(i-1>=0&&a[i-1][j]==1)
                    {
                        Pair x=p[i-1][j];
                        if(!hs.contains(p[i-1][j]))
                        {
                            f=s[x.a][x.b];
                             hs.add(x);
                        }
                    }
                    if(j-1>=0&&a[i][j-1]==1)
                    {
                        Pair x=p[i][j-1];
                        if(!hs.contains(p[i][j-1]))
                        {
                            g=s[x.a][x.b];
                             hs.add(x);
                        }
                    }
                    ans+=d+e+f+g;
                    /*if(i==2&&j==1)
                    {
                        System.out.println(d+" "+e+" "+f+" "+g);
                    }*/
                    pw.print(ans);
                }
                else
                    pw.print(c[i][j]);
            }
            pw.println(" ");
        }

          //System.out.println(p[2][0]+" "+p[2][2]+" "+p[3][1]+" "+p[1][1]);

        pw.close();
    }

    public static long  ways(int n, int r, long MOD)
    {
      //  vector<long long> f(n + 1,1);
        long f[]=new long[n+1];
        Arrays.fill(f,1);
        for (int i=2; i<=n;i++)
            f[i]= (f[i-1]*i) % MOD;
        return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
    }
    public static long  InverseEuler(long n, long MOD)
    {
        return pow(n,MOD-2,MOD);
    }
    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;
    }

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

public static int gcd(int x,int y)
{
    if(x%y==0)
        return y;
    else
        return gcd(y,x%y);
}
public static int abs(int a,int b)
{
    return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
    return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
public static int min(int a,int b)
{
    if(a>b)
        return b;
    else
        return a;
}
public static long max(long a,long b)
{
    if(a>b)
        return a;
    else
        return b;
}
public static long min(long a,long b)
{
    if(a>b)
        return b;
    else
        return a;
}

static boolean isPowerOfTwo (long v) {
    return (v & (v - 1)) == 0;
}
public static long pow(long n,long p,long m)
{
     long  result = 1;
      if(p==0)
        return 1;
    if (p==1)
        return n;
    while(p!=0)
    {
        if(p%2==1)
            result *= n;
        if(result>=m)
        result%=m;
        p >>=1;
        n*=n;
        if(n>=m)
        n%=m;
    }
    return result;
}
public static long pow(long n,long p)
{
    long  result = 1;
      if(p==0)
        return 1;
    if (p==1)
        return n;
    while(p!=0)
    {
        if(p%2==1)
            result *= n;
        p >>=1;
        n*=n;
    }
    return result;

}
static class Pair implements Comparable<Pair>
{
    int a,b;
    Pair (int a,int b)
    {
        this.a=a;
        this.b=b;
    }

    public int compareTo(Pair o) {
        // TODO Auto-generated method stub
        if(this.a!=o.a)
        return Integer.compare(this.a,o.a);
        else
            return Integer.compare(this.b, o.b);
        //return 0;
    }
    public boolean equals(Object o) {
        if (o instanceof Pair) {
            Pair p = (Pair)o;
            return p.a == a && p.b == b;
        }
        return false;
    }
    public int hashCode() {
        return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
    }
}

static long sort(int a[],int n)
{   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;  }

   static  class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public 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++];
        }

        public int readInt()
        {
            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;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public long readLong() {
            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;
        }
        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

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

     static class OutputWriter
    {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream)
        {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer)
        {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects)
        {
            for (int i = 0; i < objects.length; i++)
            {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects)
        {
            print(objects);
            writer.println();
        }

        public void close()
        {
            writer.close();
        }

        public void flush()
        {
            writer.flush();
        }

    }
    /* USAGE

    //initialize
        InputReader in      = new InputReader(System.in);
        OutputWriter out    =   new OutputWriter(System.out);

    //read int
    int i = in.readInt();
    //read string
    String s = in.readString();
    //read int array of size N
    int[] x = IOUtils.readIntArray(in,N);
    //printline
    out.printLine("X");

    //flush output
    out.flush();

    //remember to close the
    //outputstream, at the end
    out.close();

    */
  static   class IOUtils {

        public static int[] readIntArray(InputReader in, int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = in.readInt();
            return array;
    }
    }
//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    //StringBuilder sb=new StringBuilder("");
     //InputReader in = new InputReader(System.in);
  // OutputWriter out = new OutputWriter(System.out);
    //PrintWriter pw=new PrintWriter(System.out);
    //String line=br.readLine().trim();

    //int t=Integer.parseInt(br.readLine());
  //    while(t-->0)
    //{
    //int n=Integer.parseInt(br.readLine());
    //long n=Long.parseLong(br.readLine());
    //String l[]=br.readLine().split(" ");
  //int m=Integer.parseInt(l[0]);
    //int k=Integer.parseInt(l[1]);
    //String l[]=br.readLine().split(" ");
    //l=br.readLine().split(" ");
    /*int a[]=new int[n];
    for(int i=0;i<n;i++)
    {
        a[i]=Integer.parseInt(l[i]);
    }*/
       //System.out.println(" ");

    //}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;

public class C616 {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		String[] line2 = in.readLine().split(" ");
		int n = Integer.valueOf(line2[0]);
		int m = Integer.valueOf(line2[1]);
		char[][] map = new char[n][m];
		Map<Integer, Integer> hm = new HashMap<>();
		for (int i = 0; i< n; i++ ){
			String s = in.readLine();
			for (int j =0; j < m; j++) {
				map[i][j] = s.charAt(j);
			}
		}
		// symbol ca beanything except 42 & 46
		int symbol = 1;
		for (int i = 0; i< n; i++ ){
			for (int j =0; j < m; j++) {
				if (map[i][j] == '.'){
					int count = scout(map, i,j, symbol);
					hm.put(symbol, count%10);
					symbol++;
					if ((char)symbol == '.' || (char)symbol == '*' ){
						symbol++;
					}
				}
			}
		}
		TreeSet<Integer> t = new TreeSet<>();
		for (int i = 0; i< n; i++ ){
			for (int j = 0; j < m; j++) {
				if ( map[i][j] == '*'){
					int sum = 1;
					// check neighours
					if (i>0 && map[i-1][j] != '*') {
						t.add((int) map[i-1][j]);
					}
					if (i < map.length - 1 && map[i+1][j] != '*') {
						t.add((int) map[i+1][j]);
					}
					if (j > 0 && map[i][j-1] != '*') {
						t.add((int) map[i][j-1]);
					}
					if (j < map[0].length - 1 && map[i][j+1] != '*') {
						t.add((int) map[i][j+1]);
					}
					Integer[] a = new Integer[t.size()];
					a = t.toArray(a);
					t.clear();
					for (Integer e : a) {
						sum += hm.get(e);
					}
					pw.write((char)('0' + sum%10));
				} else {
					pw.write('.');
				}
			}
				pw.write('\n');
		}
		pw.flush();
		pw.close();
	}

	private static int scout(char[][] map, int i, int j, int symbol) {
		map[i][j] = (char) symbol;
		int count = 1;
		if (i>0 && map[i-1][j] == '.') {
			count += scout(map, i-1, j, symbol);
		}
		if (i < map.length - 1 && map[i+1][j] == '.') {
			count += scout(map, i+1, j, symbol);
		}
		if (j > 0 && map[i][j-1] == '.') {
			count += scout(map, i, j-1, symbol);
		}
		if (j < map[0].length - 1 && map[i][j+1] == '.') {
			count += scout(map, i, j+1, symbol);
		}
		return count;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;

public class C616 {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		String[] line2 = in.readLine().split(" ");
		int n = Integer.valueOf(line2[0]);
		int m = Integer.valueOf(line2[1]);
		int[][] map = new int[n][m];
		Map<Integer, Integer> hm = new HashMap<>();
		for (int i = 0; i< n; i++ ){
			String s = in.readLine();
			for (int j =0; j < m; j++) {
				map[i][j] = (int) s.charAt(j);
			}
		}
		// symbol ca beanything except 42 & 46
		int symbol = 1;
		for (int i = 0; i< n; i++ ){
			for (int j =0; j < m; j++) {
				if (map[i][j] == '.'){
					int count = scout(map, i,j, symbol);
					hm.put(symbol, count%10);
					symbol++;
					if (symbol == (int)'.' || symbol == (int) '*' ){
						symbol++;
					}
				}
			}
		}
		TreeSet<Integer> t = new TreeSet<>();
		for (int i = 0; i< n; i++ ){
			for (int j = 0; j < m; j++) {
				if ( map[i][j] == (int) '*'){
					int sum = 1;
					// check neighours
					if (i>0 && map[i-1][j] != (int)'*') {
						t.add( map[i-1][j]);
					}
					if (i < map.length - 1 && map[i+1][j] != (int) '*') {
						t.add( map[i+1][j]);
					}
					if (j > 0 && map[i][j-1] != (int) '*') {
						t.add( map[i][j-1]);
					}
					if (j < map[0].length - 1 && map[i][j+1] != (int) '*') {
						t.add(map[i][j+1]);
					}
					Integer[] a = new Integer[t.size()];
					a = t.toArray(a);
					t.clear();
					for (Integer e : a) {
						sum += hm.get(e);
					}
					pw.write((char)('0' + sum%10));
				} else {
					pw.write('.');
				}
			}
				pw.write('\n');
		}
		pw.flush();
		pw.close();
	}

	private static int scout(int[][] map, int i, int j, int symbol) {
		map[i][j] = symbol;
		int count = 1;
		if (i>0 && map[i-1][j] == (int) '.') {
			count += scout(map, i-1, j, symbol);
		}
		if (i < map.length - 1 && map[i+1][j] == (int) '.') {
			count += scout(map, i+1, j, symbol);
		}
		if (j > 0 && map[i][j-1] == (int)'.') {
			count += scout(map, i, j-1, symbol);
		}
		if (j < map[0].length - 1 && map[i][j+1] == (int) '.') {
			count += scout(map, i, j+1, symbol);
		}
		return count;
	}

}


import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;

public class C493 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		TreeSet<PtData> tree = new TreeSet<>();
		int n = in.nextInt();
		int dist = in.nextInt();
		tree.add(PtData.nu(dist, 1, 0));
		tree.add(PtData.nu(dist, -1, 0));
		for (int i = 1; i<n; i++) {
			dist = in.nextInt();
			tree.add(PtData.nu(dist, 1, 0));
		}
		int m = in.nextInt();
		for (int i = 0; i<m ; i++) {
			dist = in.nextInt();
			tree.add(PtData.nu(dist, 0, 1));
		}
		in.close();
		int p1 = 3*n, p2 = 3*m;
		int maxDif = p1 - p2;
		int mxP1= p1, mxP2 = p2;
		Iterator<PtData> iter = tree.iterator();
		while (iter.hasNext()) {
			PtData p = iter.next();
			p1 -= p.t1;
			p2 -= p.t2;
			if (p1 - p2 > maxDif) {
				maxDif = p1 - p2;
				mxP1 = p1;
				mxP2 = p2;
			}
		}
		System.out.printf("%d:%d\n", mxP1, mxP2);

	}
}

class PtData implements Comparable<PtData>{
	int x;
	int t1;
	int t2;

	private PtData(int x, int t1, int t2) {
		this.x = x;
		this.t1 = t1;
		this.t2 = t2;
	}

	static PtData nu(int dist, int pts1, int pts2) {
		return new PtData(dist, pts1, pts2);
	}

	@Override
	public int compareTo(PtData p) {
		int cmp = Integer.compare(this.x, p.x);
		if (cmp == 0) {
			this.t1 += p.t1;
			this.t2 += p.t2;
			p.t1 = this.t1;
			p.t2 = this.t2;
		}
		return cmp;
	}

	public String toString() {
		return String.format("%d,  %d, %d)", this.x, this.t1, this.t2);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;

public class C616 {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		String[] line2 = in.readLine().split(" ");
		int n = Integer.valueOf(line2[0]);
		int m = Integer.valueOf(line2[1]);
		char[][] map = new char[n][m];
		Map<Integer, Integer> hm = new HashMap<>();
		for (int i = 0; i< n; i++ ){
			String s = in.readLine();
			for (int j =0; j < m; j++) {
				map[i][j] = s.charAt(j);
			}
		}
		// symbol ca beanything except 42 & 46
		int symbol = 1;
		for (int i = 0; i< n; i++ ){
			for (int j =0; j < m; j++) {
				if (map[i][j] == '.'){
					int count = scout(map, i,j, symbol);
					hm.put(symbol, count%10);
					symbol++;
					if ((char)symbol == '.' || (char)symbol == '*' ){
						symbol++;
					}
				}
			}
		}
		TreeSet<Integer> t = new TreeSet<>();
		for (int i = 0; i< n; i++ ){
			for (int j = 0; j < m; j++) {
				if ( map[i][j] == '*'){
					int sum = 1;
					// check neighours
					if (i>0 && map[i-1][j] != '*') {
						t.add((int) map[i-1][j]);
					}
					if (i < map.length - 1 && map[i+1][j] != '*') {
						t.add((int) map[i+1][j]);
					}
					if (j > 0 && map[i][j-1] != '*') {
						t.add((int) map[i][j-1]);
					}
					if (j < map[0].length - 1 && map[i][j+1] != '*') {
						t.add((int) map[i][j+1]);
					}
					Integer[] a = new Integer[t.size()];
					a = t.toArray(a);
					t.clear();
					for (Integer e : a) {
						sum += hm.get(e);
					}
					pw.write((char)('0' + sum%10));
				} else {
					pw.write('.');
				}
			}
				pw.write('\n');
		}
		pw.flush();
		pw.close();
	}

	private static int scout(char[][] map, int i, int j, int symbol) {
		map[i][j] = (char) symbol;
		int count = 1;
		if (i>0 && map[i-1][j] == '.') {
			count += scout(map, i-1, j, symbol);
		}
		if (i < map.length - 1 && map[i+1][j] == '.') {
			count += scout(map, i+1, j, symbol);
		}
		if (j > 0 && map[i][j-1] == '.') {
			count += scout(map, i, j-1, symbol);
		}
		if (j < map[0].length - 1 && map[i][j+1] == '.') {
			count += scout(map, i, j+1, symbol);
		}
		return count;
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
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);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        out.printf("%c", '.');
                    } else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        out.printf("%d", res);
                    }

                }
                out.printf("\n");
            }
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
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);
        OutputWriter out = new OutputWriter(outputStream);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') out.print('.');
                    else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        out.print(res);
                    }

                }
                out.println();
            }
            out.flush();
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;
        private ArrayList<String> res = new ArrayList<>();
        private StringBuilder sb = new StringBuilder("");

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer, false);
        }

        public void println() {
            res.add(sb.toString());
            sb = new StringBuilder("");
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                sb.append(objects[i]);
            }
        }

        public void close() {
            writer.flush();
            writer.close();
        }

        public void flush() {
            for (String str : res) writer.printf("%s\n", str);
            res.clear();
            sb = new StringBuilder("");
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') out.print('.');
                    else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        out.print(res);
                    }

                }
                out.println();
            }
            out.flush();
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;
        private ArrayList<String> res = new ArrayList<>();
        private StringBuilder sb = new StringBuilder("");

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer, false);
        }

        public void println() {
            res.add(sb.toString());
            sb = new StringBuilder("");
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                sb.append(objects[i]);
            }
        }

        public void close() {
            writer.flush();
            writer.close();
        }

        public void flush() {
            for (String str : res) writer.printf("%s\n", str);
            res.clear();
            sb = new StringBuilder("");
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

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, false);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        out.printf("%c", '.');
                    } else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        out.printf("%d", res);
                    }

                }
                out.printf("\n");
            }
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

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);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        out.printf("%c", '.');
                    } else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        out.printf("%d", res);
                    }

                }
                out.printf("\n");
            }
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
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);
        OutputWriter out = new OutputWriter(outputStream);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            ArrayList<String> ans = new ArrayList<>();
            StringBuilder sb;
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                sb = new StringBuilder();
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') sb.append('.');
                    else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        sb.append(res);
                    }
                }
                ans.add(sb.toString());
            }
            for (String str : ans) out.printLine(str);
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
            writer.flush();
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
            writer.flush();
        }

        public void close() {
            writer.close();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
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);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            ArrayList<String> ans = new ArrayList<>();
            StringBuilder sb;
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                sb = new StringBuilder();
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') sb.append('.');
                    else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        sb.append(res);
                    }

                }
                ans.add(sb.toString());
            }
            for (String str : ans) out.printf("%s\n", str);
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
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);
        OutputWriter out = new OutputWriter(outputStream);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') out.print('.');
                    else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        out.print(res);
                    }

                }
                out.println();
            }
            out.flush();
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;
        private ArrayList<String> res = new ArrayList<>();
        private StringBuilder sb = new StringBuilder("");

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println() {
            res.add(sb.toString());
            sb = new StringBuilder("");
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                sb.append(objects[i]);
            }
        }

        public void close() {
//        flush();
            writer.close();
        }

        public void flush() {
            for (String str : res) writer.printf("%s\n", str);
            res.clear();
            sb = new StringBuilder("");
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
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);
        OutputWriter out = new OutputWriter(outputStream);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') out.print('.');
                    else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        out.print(res);
                    }

                }
                out.println();
            }
            out.flush();
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;
        private ArrayList<String> res = new ArrayList<>();
        private StringBuilder sb = new StringBuilder("");

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println() {
            res.add(sb.toString());
            sb = new StringBuilder("");
//        writer.println();
//        writer.flush();
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                sb.append(objects[i]);
            }
//        writer.println();
//        writer.flush();
        }

        public void close() {
//        flush();
            writer.close();
        }

        public void flush() {
            for (String str : res) writer.printf("%s\n", str);
            res.clear();
            sb = new StringBuilder("");
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
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);
        OutputWriter out = new OutputWriter(outputStream);
        CTheLabyrinth solver = new CTheLabyrinth();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheLabyrinth {
        private int n;
        private int m;

        private int index(int i, int j) {
            return i * m + j;
        }

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

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            char[][] arr = new char[n][m];
            CTheLabyrinth.DisjointSet ds = new CTheLabyrinth.DisjointSet(n * m);
            for (int i = 0; i < n; i++) {
                String str = in.nextLine();
                for (int j = 0; j < m; j++) arr[i][j] = str.charAt(j);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') {
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') ds.union(index(i, j), index(i - 1, j));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') ds.union(index(i, j), index(i, j + 1));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') ds.union(index(i, j), index(i + 1, j));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') ds.union(index(i, j), index(i, j - 1));
                    }
                }
            }
            HashSet<Integer> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (arr[i][j] == '.') out.print('.');
                    else {
                        hs.clear();
                        if (isValid(i - 1, j) && arr[i - 1][j] == '.') hs.add(ds.root(index(i - 1, j)));
                        if (isValid(i, j + 1) && arr[i][j + 1] == '.') hs.add(ds.root(index(i, j + 1)));
                        if (isValid(i + 1, j) && arr[i + 1][j] == '.') hs.add(ds.root(index(i + 1, j)));
                        if (isValid(i, j - 1) && arr[i][j - 1] == '.') hs.add(ds.root(index(i, j - 1)));
                        int res = 0;
                        for (int x : hs) res += ds.setSize[x];
                        res++;
                        res = Util.mod(res, 10);
                        out.print(res);
                    }

                }
                out.println();
            }
            out.flush();
        }

        static class DisjointSet {
            private int[] parent;
            private int[] setSize;
            private int numOfSets;

            private DisjointSet(int n) {
                parent = new int[n];
                setSize = new int[n];
                for (int i = 0; i < n; i++) {
                    setSize[i] = 1;
                    parent[i] = i;
                }
                numOfSets = n;
            }

            private int root(int x) {
                if (x == parent[x]) return x;
                return parent[x] = root(parent[x]);
            }

            private boolean _union(int n1, int n2) {
                if (n1 == n2) return false;
                if (setSize[n1] > setSize[n2]) {
                    parent[n2] = parent[n1];
                    setSize[n1] += setSize[n2];
                } else {
                    parent[n1] = parent[n2];
                    setSize[n2] += setSize[n1];
                }
                numOfSets--;
                return true;
            }

            private boolean union(int n1, int n2) {
                return _union(root(n1), root(n2));
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public 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++];
        }

        public 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 = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }

    static class Util {
        public static int mod(int a, int mod) {
            int res = a % mod;
            return res >= 0 ? res : res + mod;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;
        private ArrayList<String> res = new ArrayList<>();
        private StringBuilder sb = new StringBuilder("");

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println() {
            res.add(sb.toString());
            sb = new StringBuilder("");
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                sb.append(objects[i]);
            }
        }

        public void close() {
            // writer.flush();
            writer.close();
        }

        public void flush() {
            for (String str : res) writer.printf("%s\n", str);
            res.clear();
            sb = new StringBuilder("");
        }

    }
}