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

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

class Cell {
    int x, y;

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

class Task {

    private Map<Integer, Integer> map = new HashMap<>();

    private char tab[][];

    private int count[][];

    private int n,m;

    public void solve(InputReader in, OutputWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        tab = new char[n][m];
        count = new int[n][m];
        for(int i=0;i<n;i++) {
            tab[i] = in.next().toCharArray();
        }
        int counter = 1;
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(tab[i][j] == '.') {
                    int c = bfs(i,j,counter);
                    map.put(counter, c);
                    counter++;
                }
            }
        }
        Set<Integer> set = new HashSet<>();
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(tab[i][j] == '*') {
                    for(int k=0;k<4;k++) {
                        if(i+moveX[k] >=0 && i+moveX[k] < n && j+moveY[k] >=0 && j+moveY[k] < m && tab[i+moveX[k]][j+moveY[k]] != '*') {
                            set.add(count[i+moveX[k]][j+moveY[k]]);
                        }
                    }
                    int total = 1;
                    for(int element : set) {
                        total += map.get(element);
                    }
                    set.clear();
                    System.out.print(total);
                } else {
                    System.out.print('.');
                }
            }
            System.out.println();
        }
    }

    private int moveX[] = {-1,1,0,0};

    private int moveY[] = {0,0,-1,1};

    private int bfs(int i, int j, int counter) {
        Queue<Cell> Q = new ArrayDeque<>();
        Q.add(new Cell(i,j));
        int c = 0;
        while(!Q.isEmpty()) {
            Cell cell = Q.poll();
            tab[cell.x][cell.y] = '-';
            count[cell.x][cell.y] = counter;
            c++;
            for(int k=0;k<4;k++) {
                if(inside(cell, k) && tab[cell.x+moveX[k]][cell.y+moveY[k]] == '.') {
                    Q.add(new Cell(cell.x+moveX[k], cell.y+moveY[k]));
                }
            }
        }
        return c;
    }

    private boolean inside(Cell cell, int k) {
        return cell.x + moveX[k] >= 0 && cell.x + moveX[k] < n && cell.y + moveY[k] >=0 && cell.y + moveY[k] < m;
    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public boolean hasNext() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if ( line == null ) {
                    return false;
                }
                tokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }

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

    public double nextDouble() { return Double.parseDouble(next());}
}
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();
    }
}


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

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

class Cell {
    int x, y;

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

class Task {

    private Map<Integer, Integer> map = new HashMap<>();

    private char tab[][];

    private int count[][];

    private int n,m;

    public void solve(InputReader in, OutputWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        tab = new char[n][m];
        count = new int[n][m];
        for(int i=0;i<n;i++) {
            tab[i] = in.next().toCharArray();
        }
        int counter = 1;
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(tab[i][j] == '.') {
                    int c = bfs(i,j,counter);
                    map.put(counter, c);
                    counter++;
                }
            }
        }
        Set<Integer> set = new HashSet<>();
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(tab[i][j] == '*') {
                    for(int k=0;k<4;k++) {
                        if(i+moveX[k] >=0 && i+moveX[k] < n && j+moveY[k] >=0 && j+moveY[k] < m && tab[i+moveX[k]][j+moveY[k]] != '*') {
                            set.add(count[i+moveX[k]][j+moveY[k]]);
                        }
                    }
                    int total = 1;
                    for(int element : set) {
                        total += map.get(element);
                    }
                    set.clear();
                    out.print(total % 10);
                } else {
                    out.print(".");
                }
            }
            out.printLine();
        }
    }

    private int moveX[] = {-1,1,0,0};

    private int moveY[] = {0,0,-1,1};

    private int bfs(int i, int j, int counter) {
        Queue<Cell> Q = new ArrayDeque<>();
        Q.add(new Cell(i,j));
        int c = 0;
        tab[i][j] = '-';
        while(!Q.isEmpty()) {
            Cell cell = Q.poll();
            count[cell.x][cell.y] = counter;
            c++;
            for(int k=0;k<4;k++) {
                if(inside(cell, k) && tab[cell.x+moveX[k]][cell.y+moveY[k]] == '.') {
                    Q.add(new Cell(cell.x+moveX[k], cell.y+moveY[k]));
                    tab[cell.x+moveX[k]][cell.y+moveY[k]] = '-';
                }
            }
        }
        return c;
    }

    private boolean inside(Cell cell, int k) {
        return cell.x + moveX[k] >= 0 && cell.x + moveX[k] < n && cell.y + moveY[k] >=0 && cell.y + moveY[k] < m;
    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public boolean hasNext() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if ( line == null ) {
                    return false;
                }
                tokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }

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

    public double nextDouble() { return Double.parseDouble(next());}
}
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();
    }
}


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

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

class Cell {
    int x, y;

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

class Task {

    private Map<Integer, Integer> map = new HashMap<>();

    private char tab[][];

    private int count[][];

    private int n,m;

    public void solve(InputReader in, OutputWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        tab = new char[n][m];
        count = new int[n][m];
        for(int i=0;i<n;i++) {
            tab[i] = in.next().toCharArray();
        }
        int counter = 1;
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(tab[i][j] == '.') {
                    int c = bfs(i,j,counter);
                    map.put(counter, c);
                    counter++;
                }
            }
        }
        Set<Integer> set = new HashSet<>();
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(tab[i][j] == '*') {
                    for(int k=0;k<4;k++) {
                        if(i+moveX[k] >=0 && i+moveX[k] < n && j+moveY[k] >=0 && j+moveY[k] < m && tab[i+moveX[k]][j+moveY[k]] != '*') {
                            set.add(count[i+moveX[k]][j+moveY[k]]);
                        }
                    }
                    int total = 1;
                    for(int element : set) {
                        total += map.get(element);
                    }
                    set.clear();
                    System.out.print(total % 10);
                } else {
                    System.out.print('.');
                }
            }
            System.out.println();
        }
    }

    private int moveX[] = {-1,1,0,0};

    private int moveY[] = {0,0,-1,1};

    private int bfs(int i, int j, int counter) {
        Queue<Cell> Q = new ArrayDeque<>();
        Q.add(new Cell(i,j));
        int c = 0;
        while(!Q.isEmpty()) {
            Cell cell = Q.poll();
            tab[cell.x][cell.y] = '-';
            count[cell.x][cell.y] = counter;
            c++;
            for(int k=0;k<4;k++) {
                if(inside(cell, k) && tab[cell.x+moveX[k]][cell.y+moveY[k]] == '.') {
                    Q.add(new Cell(cell.x+moveX[k], cell.y+moveY[k]));
                }
            }
        }
        return c;
    }

    private boolean inside(Cell cell, int k) {
        return cell.x + moveX[k] >= 0 && cell.x + moveX[k] < n && cell.y + moveY[k] >=0 && cell.y + moveY[k] < m;
    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public boolean hasNext() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if ( line == null ) {
                    return false;
                }
                tokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }

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

    public double nextDouble() { return Double.parseDouble(next());}
}
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();
    }
}


import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Edu5C {
    static boolean visited[][];
    static int n;
    static int m;
    static char[][] grid;
    static int counter, SCC;

    static Stack<Pair> stack;
    static int[][] dfs_num, dfs_low;
    static boolean assigned[][];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        sc.nextLine();
        grid = new char[n][m];
        visited = new boolean[n][m];
        for(int i=0; i<n; i++){
            grid[i] = sc.nextLine().toCharArray();
        }
        go();
//      for(int i=0; i<n; i++)
//          System.out.println(Arrays.toString(dfs_low[i]));
        visited = new boolean[n][m];
        assigned = new boolean[n][m];
        int[][] countSCC = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(grid[i][j] != '.' || visited[i][j])
                    continue;
                int count = getCount(i,j);
                assignCount(i,j,count,countSCC);
            }
        }
        int [][] res = new int[n][m];
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++){
                if(grid[i][j] == '*'){
                    HashSet<Integer> added = new HashSet<Integer>(4);
                    res[i][j] = 1;
                    if(i>0){
                        res[i][j] += countSCC[i-1][j];
                        added.add(dfs_low[i-1][j]);
                    }
                    if(i<n-1 && !added.contains(dfs_low[i+1][j])){
                        res[i][j] += countSCC[i+1][j];
                        added.add(dfs_low[i+1][j]);
                    }
                    if(j>0 && !added.contains(dfs_low[i][j-1])){
                        res[i][j] += countSCC[i][j-1];
                        added.add(dfs_low[i][j-1]);
                    }
                    if(j<m-1 && !added.contains(dfs_low[i][j+1])){
                        res[i][j] += countSCC[i][j+1];
                        added.add(dfs_low[i][j+1]);
                    }
                }
            }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(res[i][j]>0)
                    out.print(res[i][j]);
                else
                    out.print('.');
            }
            out.println();
        }
        out.flush();

    }
    static void assignCount(int i, int j, int c, int[][] cSCC){
        if(i<0 || j<0 || i>=n || j>=m || assigned[i][j])
            return;
        cSCC[i][j] = c;
        assigned[i][j] = true;
        if(i>0 && grid[i-1][j] == '.')
            assignCount(i-1,j,c,cSCC);
        if(j>0 && grid[i][j-1] == '.')
            assignCount(i,j-1,c,cSCC);
        if(i<n-1 && grid[i+1][j] == '.')
            assignCount(i+1,j,c,cSCC);
        if(j<m-1 && grid[i][j+1] == '.')
            assignCount(i,j+1,c,cSCC);

    }
    static int getCount(int i, int j){

        if(i<0 || j<0 || i>=n || j>=m)
            return 0;
        if(grid[i][j] != '.' || visited[i][j])
            return 0;
        visited[i][j] = true;
        int right = getCount(i+1,j);
        int down = getCount(i,j+1);
        int up = getCount(i,j-1);
        int left = getCount(i-1,j);

        return 1 + right + down + up + left;
    }
    public static void tarjanSCC(int i,int j)
    {
        dfs_num[i][j] = dfs_low[i][j] = ++counter;
        stack.push(new Pair(i,j));
        visited[i][j] = true;
        if(i>0 && grid[i-1][j] == '.'){
            if(dfs_num[i-1][j] == 0)
                tarjanSCC(i-1,j);
            if(visited[i-1][j])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i-1][j]);
        }
        if(i<n-1 && grid[i+1][j] == '.'){
            if(dfs_num[i+1][j] == 0)
                tarjanSCC(i+1,j);
            if(visited[i+1][j])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i+1][j]);
        }
        if(j>0 && grid[i][j-1] == '.'){
            if(dfs_num[i][j-1] == 0)
                tarjanSCC(i,j-1);
            if(visited[i][j-1])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i][j-1]);
        }
        if(j<m-1 && grid[i][j+1] == '.'){
            if(dfs_num[i][j+1] == 0)
                tarjanSCC(i,j+1);
            if(visited[i][j+1])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i][j+1]);
        }

        if(dfs_num[i][j]==dfs_low[i][j])
        {
            //Discovered an SCC
            SCC++;
            while(true)     //vertices in the discovered SCC
            {
                Pair v = stack.pop();
                visited[v.i][v.j] = false;
                if(v.i == i && v.j == j)
                    break;
            }
        }
    }
    static void go()
    {
        counter = SCC = 0;
        dfs_num = new int[n][m];
        dfs_low = new int[n][m];
        visited = new boolean[n][m];
        stack = new Stack<Pair>();

        for(int i = 0; i < n; i++)
            for(int j=0; j<m; j++)
                if(grid[i][j] == '.' && dfs_num[i][j]==0)
                    tarjanSCC(i,j);
    }

    static class Pair{
        int i,j;
        public Pair(int i, int j){
            this.i = i;
            this.j = j;
        }
    }

}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Edu5C {
    static boolean visited[][];
    static int n;
    static int m;
    static char[][] grid;
    static int setNo = 1;
    static int belongsTo[][];
    static boolean assigned[][];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        sc.nextLine();
        grid = new char[n][m];
        visited = new boolean[n][m];
        for(int i=0; i<n; i++){
            grid[i] = sc.nextLine().toCharArray();
        }

        visited = new boolean[n][m];
        assigned = new boolean[n][m];
        belongsTo = new int[n][m];
        int[][] countSCC = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(grid[i][j] != '.' || visited[i][j])
                    continue;
                int count = getCount(i,j);
                assignCount(i,j,count,countSCC,setNo);
                setNo++;
            }
        }

        int [][] res = new int[n][m];
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++){
                if(grid[i][j] == '*'){
                    HashSet<Integer> added = new HashSet<Integer>(4);
                    res[i][j] = 1;
                    if(i>0){
                        res[i][j] += countSCC[i-1][j];
                        added.add(belongsTo[i-1][j]);

                    }
                    if(i<n-1 && !added.contains(belongsTo[i+1][j])){
                        res[i][j] += countSCC[i+1][j];
                        added.add(belongsTo[i+1][j]);
                        //System.out.println(2);
                    }
                    if(j>0 && !added.contains(belongsTo[i][j-1])){
                        res[i][j] += countSCC[i][j-1];
                        //System.out.println(added);
                        added.add(belongsTo[i][j-1]);
                    }
                    if(j<m-1 && !added.contains(belongsTo[i][j+1])){
                        res[i][j] += countSCC[i][j+1];
                        added.add(belongsTo[i][j+1]);
                        //System.out.println(4);
                    }
                }
            }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(res[i][j]>0)
                    out.print(res[i][j]%10);
                else
                    out.print('.');
            }
            out.println();
        }
        out.flush();

    }
    static void assignCount(int i, int j, int c, int[][] cSCC,int set){
        if(i<0 || j<0 || i>=n || j>=m || assigned[i][j])
            return;
        cSCC[i][j] = c;
        assigned[i][j] = true;
        belongsTo[i][j] = set;
        if(i>0 && grid[i-1][j] == '.')
            assignCount(i-1,j,c,cSCC,set);
        if(j>0 && grid[i][j-1] == '.')
            assignCount(i,j-1,c,cSCC,set);
        if(i<n-1 && grid[i+1][j] == '.')
            assignCount(i+1,j,c,cSCC,set);
        if(j<m-1 && grid[i][j+1] == '.')
            assignCount(i,j+1,c,cSCC,set);

    }
    static int getCount(int i, int j){

        if(i<0 || j<0 || i>=n || j>=m)
            return 0;
        if(grid[i][j] != '.' || visited[i][j])
            return 0;
        visited[i][j] = true;
        int right = getCount(i+1,j);
        int down = getCount(i,j+1);
        int up = getCount(i,j-1);
        int left = getCount(i-1,j);

        return 1 + right + down + up + left;
    }

}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Edu5C {
    static boolean visited[][];
    static int n;
    static int m;
    static char[][] grid;
    static int counter, SCC;
    static int setNo = 1;
    static int belongsTo[][];
    static Stack<Pair> stack;
    static int[][] dfs_num, dfs_low;
    static boolean assigned[][];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        sc.nextLine();
        grid = new char[n][m];
        visited = new boolean[n][m];
        for(int i=0; i<n; i++){
            grid[i] = sc.nextLine().toCharArray();
        }
        go();
//      for(int i=0; i<n; i++)
//          System.out.println(Arrays.toString(dfs_low[i]));
        visited = new boolean[n][m];
        assigned = new boolean[n][m];
        belongsTo = new int[n][m];
        int[][] countSCC = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(grid[i][j] != '.' || visited[i][j])
                    continue;
                int count = getCount(i,j);
                assignCount(i,j,count,countSCC,setNo);
                setNo++;
            }
        }
//      for(int i=0; i<n; i++)
//          System.out.println(Arrays.toString(countSCC[i]));
        int [][] res = new int[n][m];

//      for(int i=0; i<n; i++)
//          System.out.println(dfs_num[i]);
//      for(int i=0; i<n; i++)
//          System.out.println(Arrays.toString(belongsTo[i]));
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++){
                if(grid[i][j] == '*'){
                    HashSet<Integer> added = new HashSet<Integer>(4);
                    res[i][j] = 1;
                    if(i>0){
                        res[i][j] += countSCC[i-1][j];
                        added.add(belongsTo[i-1][j]);

                    }
                    if(i<n-1 && !added.contains(belongsTo[i+1][j])){
                        res[i][j] += countSCC[i+1][j];
                        added.add(belongsTo[i+1][j]);
                        //System.out.println(2);
                    }
                    if(j>0 && !added.contains(belongsTo[i][j-1])){
                        res[i][j] += countSCC[i][j-1];
                        //System.out.println(added);
                        added.add(belongsTo[i][j-1]);
                    }
                    if(j<m-1 && !added.contains(belongsTo[i][j+1])){
                        res[i][j] += countSCC[i][j+1];
                        added.add(belongsTo[i][j+1]);
                        //System.out.println(4);
                    }
                }
            }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(res[i][j]>0)
                    out.print(res[i][j]%10);
                else
                    out.print('.');
            }
            out.println();
        }
        out.flush();

    }
    static void assignCount(int i, int j, int c, int[][] cSCC,int set){
        if(i<0 || j<0 || i>=n || j>=m || assigned[i][j])
            return;
        cSCC[i][j] = c;
        assigned[i][j] = true;
        belongsTo[i][j] = set;
        if(i>0 && grid[i-1][j] == '.')
            assignCount(i-1,j,c,cSCC,set);
        if(j>0 && grid[i][j-1] == '.')
            assignCount(i,j-1,c,cSCC,set);
        if(i<n-1 && grid[i+1][j] == '.')
            assignCount(i+1,j,c,cSCC,set);
        if(j<m-1 && grid[i][j+1] == '.')
            assignCount(i,j+1,c,cSCC,set);

    }
    static int getCount(int i, int j){

        if(i<0 || j<0 || i>=n || j>=m)
            return 0;
        if(grid[i][j] != '.' || visited[i][j])
            return 0;
        visited[i][j] = true;
        int right = getCount(i+1,j);
        int down = getCount(i,j+1);
        int up = getCount(i,j-1);
        int left = getCount(i-1,j);

        return 1 + right + down + up + left;
    }
    public static void tarjanSCC(int i,int j)
    {
        dfs_num[i][j] = dfs_low[i][j] = ++counter;
        stack.push(new Pair(i,j));
        visited[i][j] = true;
        if(i>0 && grid[i-1][j] == '.'){
            if(dfs_num[i-1][j] == 0)
                tarjanSCC(i-1,j);
            if(visited[i-1][j])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i-1][j]);
        }
        if(i<n-1 && grid[i+1][j] == '.'){
            if(dfs_num[i+1][j] == 0)
                tarjanSCC(i+1,j);
            if(visited[i+1][j])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i+1][j]);
        }
        if(j>0 && grid[i][j-1] == '.'){
            if(dfs_num[i][j-1] == 0)
                tarjanSCC(i,j-1);
            if(visited[i][j-1])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i][j-1]);
        }
        if(j<m-1 && grid[i][j+1] == '.'){
            if(dfs_num[i][j+1] == 0)
                tarjanSCC(i,j+1);
            if(visited[i][j+1])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i][j+1]);
        }

        if(dfs_num[i][j]==dfs_low[i][j])
        {
            //Discovered an SCC
            SCC++;
            while(true)     //vertices in the discovered SCC
            {
                Pair v = stack.pop();
                visited[v.i][v.j] = false;
                if(v.i == i && v.j == j)
                    break;
            }
        }
    }
    static void go()
    {
        counter = SCC = 0;
        dfs_num = new int[n][m];
        dfs_low = new int[n][m];
        visited = new boolean[n][m];
        stack = new Stack<Pair>();

        for(int i = 0; i < n; i++)
            for(int j=0; j<m; j++)
                if(grid[i][j] == '.' && dfs_num[i][j]==0)
                    tarjanSCC(i,j);
    }

    static class Pair{
        int i,j;
        public Pair(int i, int j){
            this.i = i;
            this.j = j;
        }
    }

}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Edu5C {
    static boolean visited[][];
    static int n;
    static int m;
    static char[][] grid;
    static int counter, SCC;
    static int setNo = 1;
    static int belongsTo[][];
    static Stack<Pair> stack;
    static int[][] dfs_num, dfs_low;
    static boolean assigned[][];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        sc.nextLine();
        grid = new char[n][m];
        visited = new boolean[n][m];
        for(int i=0; i<n; i++){
            grid[i] = sc.nextLine().toCharArray();
        }
        go();
//      for(int i=0; i<n; i++)
//          System.out.println(Arrays.toString(dfs_low[i]));
        visited = new boolean[n][m];
        assigned = new boolean[n][m];
        belongsTo = new int[n][m];
        int[][] countSCC = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(grid[i][j] != '.' || visited[i][j])
                    continue;
                int count = getCount(i,j);
                assignCount(i,j,count,countSCC,setNo);
                setNo++;
            }
        }
//      for(int i=0; i<n; i++)
//          System.out.println(Arrays.toString(countSCC[i]));
        int [][] res = new int[n][m];

//      for(int i=0; i<n; i++)
//          System.out.println(dfs_num[i]);
//      for(int i=0; i<n; i++)
//          System.out.println(Arrays.toString(belongsTo[i]));
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++){
                if(grid[i][j] == '*'){
                    HashSet<Integer> added = new HashSet<Integer>(4);
                    res[i][j] = 1;
                    if(i>0){
                        res[i][j] += countSCC[i-1][j];
                        added.add(belongsTo[i-1][j]);

                    }
                    if(i<n-1 && !added.contains(belongsTo[i+1][j])){
                        res[i][j] += countSCC[i+1][j];
                        added.add(belongsTo[i+1][j]);
                        //System.out.println(2);
                    }
                    if(j>0 && !added.contains(belongsTo[i][j-1])){
                        res[i][j] += countSCC[i][j-1];
                        //System.out.println(added);
                        added.add(belongsTo[i][j-1]);
                    }
                    if(j<m-1 && !added.contains(belongsTo[i][j+1])){
                        res[i][j] += countSCC[i][j+1];
                        added.add(belongsTo[i][j+1]);
                        //System.out.println(4);
                    }
                }
            }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(res[i][j]>0)
                    out.print(res[i][j]);
                else
                    out.print('.');
            }
            out.println();
        }
        out.flush();

    }
    static void assignCount(int i, int j, int c, int[][] cSCC,int set){
        if(i<0 || j<0 || i>=n || j>=m || assigned[i][j])
            return;
        cSCC[i][j] = c;
        assigned[i][j] = true;
        belongsTo[i][j] = set;
        if(i>0 && grid[i-1][j] == '.')
            assignCount(i-1,j,c,cSCC,set);
        if(j>0 && grid[i][j-1] == '.')
            assignCount(i,j-1,c,cSCC,set);
        if(i<n-1 && grid[i+1][j] == '.')
            assignCount(i+1,j,c,cSCC,set);
        if(j<m-1 && grid[i][j+1] == '.')
            assignCount(i,j+1,c,cSCC,set);

    }
    static int getCount(int i, int j){

        if(i<0 || j<0 || i>=n || j>=m)
            return 0;
        if(grid[i][j] != '.' || visited[i][j])
            return 0;
        visited[i][j] = true;
        int right = getCount(i+1,j);
        int down = getCount(i,j+1);
        int up = getCount(i,j-1);
        int left = getCount(i-1,j);

        return 1 + right + down + up + left;
    }
    public static void tarjanSCC(int i,int j)
    {
        dfs_num[i][j] = dfs_low[i][j] = ++counter;
        stack.push(new Pair(i,j));
        visited[i][j] = true;
        if(i>0 && grid[i-1][j] == '.'){
            if(dfs_num[i-1][j] == 0)
                tarjanSCC(i-1,j);
            if(visited[i-1][j])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i-1][j]);
        }
        if(i<n-1 && grid[i+1][j] == '.'){
            if(dfs_num[i+1][j] == 0)
                tarjanSCC(i+1,j);
            if(visited[i+1][j])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i+1][j]);
        }
        if(j>0 && grid[i][j-1] == '.'){
            if(dfs_num[i][j-1] == 0)
                tarjanSCC(i,j-1);
            if(visited[i][j-1])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i][j-1]);
        }
        if(j<m-1 && grid[i][j+1] == '.'){
            if(dfs_num[i][j+1] == 0)
                tarjanSCC(i,j+1);
            if(visited[i][j+1])
                dfs_low[i][j] = Math.min(dfs_low[i][j],dfs_low[i][j+1]);
        }

        if(dfs_num[i][j]==dfs_low[i][j])
        {
            //Discovered an SCC
            SCC++;
            while(true)     //vertices in the discovered SCC
            {
                Pair v = stack.pop();
                visited[v.i][v.j] = false;
                if(v.i == i && v.j == j)
                    break;
            }
        }
    }
    static void go()
    {
        counter = SCC = 0;
        dfs_num = new int[n][m];
        dfs_low = new int[n][m];
        visited = new boolean[n][m];
        stack = new Stack<Pair>();

        for(int i = 0; i < n; i++)
            for(int j=0; j<m; j++)
                if(grid[i][j] == '.' && dfs_num[i][j]==0)
                    tarjanSCC(i,j);
    }

    static class Pair{
        int i,j;
        public Pair(int i, int j){
            this.i = i;
            this.j = j;
        }
    }

}


import java.util.ArrayList;
import java.util.Scanner;

public class CF616C {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        scanner.nextLine();

        int[][] matrix = new int[n][m];
        for (int i = 0; i < n; i++) {
            String line = scanner.nextLine();
            for (int j = 0; j < m; j++) {
                matrix[i][j] = line.charAt(j) == '.' ? -1 : 0;
            }
        }

        ArrayList<Integer> sizes = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (matrix[i][j] == -1) {
                    sizes.add(dfs(matrix, sizes.size() + 1, i, j));
                }
            }
        }

        for (int i = 0; i < n; i++) {
            char[] line = new char[m];
            for (int j = 0; j < m; j++) {
                if (matrix[i][j] == 0) {
                    int d1 = (i > 0 && matrix[i - 1][j] != 0) ? sizes.get(matrix[i - 1][j] - 1) : 0;
                    int d2 = (i < n - 1 && matrix[i + 1][j] != 0) ? sizes.get(matrix[i + 1][j] - 1) : 0;
                    int d3 = (j > 0 && matrix[i][j - 1] != 0) ? sizes.get(matrix[i][j-1] - 1) : 0;
                    int d4 = (j < m - 1 && matrix[i][j + 1] != 0) ? sizes.get(matrix[i][j+1] - 1) : 0;
                    line[j] = (char)('0' + ((d1 + d2 + d3 + d4 + 1) % 10));
                } else {
                    line[j] = '.';
                }
            }
            System.out.println(new String(line));
        }
    }

    private static int dfs(int[][] matrix, int currentIndex, int x, int y) {
        if (x < 0 || y < 0 || x >= matrix.length || y >= matrix[0].length || matrix[x][y] != -1)
            return 0;

        matrix[x][y] = currentIndex;

        return 1 +
                dfs(matrix, currentIndex, x + 1, y) +
                dfs(matrix, currentIndex, x - 1, y) +
                dfs(matrix, currentIndex, x, y + 1) +
                dfs(matrix, currentIndex, x, y - 1);
    }

}


import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class CF616C {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        scanner.nextLine();

        int[][] matrix = new int[n][m];
        for (int i = 0; i < n; i++) {
            String line = scanner.nextLine();
            for (int j = 0; j < m; j++) {
                matrix[i][j] = line.charAt(j) == '.' ? -1 : 0;
            }
        }

        ArrayList<Integer> sizes = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (matrix[i][j] == -1) {
                    sizes.add(dfs(matrix, sizes.size() + 1, i, j));
                }
            }
        }

        for (int i = 0; i < n; i++) {
            char[] line = new char[m];
            for (int j = 0; j < m; j++) {
                if (matrix[i][j] == 0) {
                    int result = 1;
                    HashSet<Integer> visited = new HashSet<>();
                    visited.add(0);
                    if (i > 0 && !visited.contains(matrix[i - 1][j])) {
                        result += sizes.get(matrix[i - 1][j] - 1);
                        visited.add(matrix[i - 1][j]);
                    }
                    if (i < n - 1 && !visited.contains(matrix[i + 1][j])) {
                        result += sizes.get(matrix[i + 1][j] - 1);
                        visited.add(matrix[i + 1][j]);
                    }
                    if (j > 0 && !visited.contains(matrix[i][j - 1])) {
                        result += sizes.get(matrix[i][j - 1] - 1);
                        visited.add(matrix[i][j - 1]);
                    }
                    if (j < m - 1 && !visited.contains(matrix[i][j + 1])) {
                        result += sizes.get(matrix[i][j + 1] - 1);
                        visited.add(matrix[i][j + 1]);
                    }

                    line[j] = (char)('0' + (result % 10));
                } else {
                    line[j] = '.';
                }
            }
            System.out.println(new String(line));
        }
    }

    private static int dfs(int[][] matrix, int currentIndex, int x, int y) {
        if (x < 0 || y < 0 || x >= matrix.length || y >= matrix[0].length || matrix[x][y] != -1)
            return 0;

        matrix[x][y] = currentIndex;

        return 1 +
                dfs(matrix, currentIndex, x + 1, y) +
                dfs(matrix, currentIndex, x - 1, y) +
                dfs(matrix, currentIndex, x, y + 1) +
                dfs(matrix, currentIndex, x, y - 1);
    }

}


import java.util.Scanner;
public class ER5_C {
    public static int n,m;
    public static char[][] map, out;
    public static boolean[][] visited;
    public static int size;
    public static void dfs(int x, int y){
        if(!(x<0 || x>=n || y<0 || y>=n)){
            if(visited[x][y] == false) {
                if (map[x][y] == '.') {
                    visited[x][y] = true;
                    size++;
                    dfs(x, y - 1);
                    dfs(x, y + 1);
                    dfs(x + 1, y);
                    dfs(x - 1, y);
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt(); m = in.nextInt();
        map = new char[n][m];
        out = new char[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.next();
            for (int j = 0; j < m; j++) {
                map[i][j] = s.charAt(j);
            }
        }

        // for each * char, calculate connected components.
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(map[i][j] == '*'){
                    // perform dfs starting here
                    map[i][j] = '.';
                    size = 0;
                    visited = new boolean[n][m];
                    dfs(i, j);
                    out[i][j] = Character.forDigit(size, 10);
                    map[i][j] = '*';
                }
                else{
                    out[i][j]='.';
                }
            }
        }
        //System.out.println("end");
        for (int i = 0; i < n; i++) {
            String s= new String(out[i]);
            System.out.println(s);
        }
    }
}


import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class ER5_C {
    public static int n,m;
    public static int idIndex = 1;
    public static char[][] map, out;
    public static int ccsize[];
    public static int corToId[][];

    public static int dfs(int i, int j, int c){
        if (i<0 || j<0 || i >=n || j >=m){
            return -1;
        }
        if(map[i][j] == '*'){
            return -1;
        }
        if(corToId[i][j] != 0){
            return corToId[i][j];
        }
        corToId[i][j]=c;
        ccsize[c]++;
        dfs(i+1, j, c);
        dfs(i-1, j, c);
        dfs(i, j+1, c);
        dfs(i, j-1, c);
        return c;
    }

    public static void main(String[] args) {
        corToId = new int[1010][1010];
        ccsize = new int[1001000];
        Scanner in = new Scanner(System.in);
        n = in.nextInt(); m = in.nextInt();
        map = new char[n][m];
        out = new char[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.next();
            for (int j = 0; j < m; j++) {
                map[i][j] = s.charAt(j);
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                dfs(i, j, idIndex++);
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(map[i][j]=='*') {
                    Set<Integer> set = new HashSet<Integer>();
                    set.add(dfs(i - 1, j, 0));
                    set.add(dfs(i + 1, j, 0));
                    set.add(dfs(i, j - 1, 0));
                    set.add(dfs(i, j +1, 0));
                    int a = 1;
                    for (Integer x : set) {
                        if (x > -1) {
                            a+=ccsize[x];
                        }
                    }
                    out[i][j] = Character.forDigit(a%10, 10);
                }
                else{
                    out[i][j] = '.';
                }
            }
        }

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

        /*
        // for each * char, calculate connected components.
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(map[i][j] == '*'){
                    // perform dfs starting here
                    //map[i][j] = '.';
                    size = 0;
                    visited = new boolean[n][m];

                    out[i][j] = Character.forDigit(size%10, 10);
                    map[i][j] = '*';
                }
                else{
                    out[i][j]='.';
                }
            }
        }
        //System.out.println("end");
        for (int i = 0; i < n; i++) {
            String s= new String(out[i]);
            System.out.println(s);
        }
        */
    }
}


import java.util.Scanner;

public class ER5_C {
    public static int n,m;
    public static char[][] map, out;
    public static boolean[][] visited;
    public static int size;
    public static void dfs(int x, int y){
        if(!(x<0 || x>=n || y<0 || y>=m)){
            if(visited[x][y] == false) {
                if (map[x][y] == '.') {
                    visited[x][y] = true;
                    size++;
                    dfs(x, y - 1);
                    dfs(x, y + 1);
                    dfs(x + 1, y);
                    dfs(x - 1, y);
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt(); m = in.nextInt();
        map = new char[n][m];
        out = new char[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.next();
            for (int j = 0; j < m; j++) {
                map[i][j] = s.charAt(j);
            }
        }

        // for each * char, calculate connected components.
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(map[i][j] == '*'){
                    // perform dfs starting here
                    map[i][j] = '.';
                    size = 0;
                    visited = new boolean[n][m];
                    dfs(i, j);
                    out[i][j] = Character.forDigit(size, 10);
                    map[i][j] = '*';
                }
                else{
                    out[i][j]='.';
                }
            }
        }
        //System.out.println("end");
        for (int i = 0; i < n; i++) {
            String s= new String(out[i]);
            System.out.println(s);
        }
    }
}


import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

/**
 * Created by baturayk on 12/01/16.
 You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle).
 Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they
 share a side.

 Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path
 of adjacent cells. It is a typical well-known definition of a connected component.

 For each impassable cell (x, y) imagine that it is an empty cell (all other cells remain unchanged) and find the size
 (the number of cells) of the connected component which contains (x, y). You should do it for each impassable cell
 independently.

 The answer should be printed as a matrix with n rows and m columns. The j-th symbol of the i-th row should be "." if
 the cell is empty at the start. Otherwise the j-th symbol of the i-th row should contain the only digit —- the answer
 modulo 10. The matrix should be printed without any spaces.

 To make your output faster it is recommended to build the output as an array of n strings having length m and print
 it as a sequence of lines. It will be much faster than writing character-by-character.

 As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use
 scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

 Input
 The first line contains two integers n, m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the field.

 Each of the next n lines contains m symbols: "." for empty cells, "*" for impassable cells.

 Output
 Print the answer as a matrix as described above. See the examples to precise the format of the output.
 *
 */
public class ER5_C {
    public static int n,m;
    public static int idIndex = 1;
    public static char[][] map, out;
    public static boolean[][] visited;
    public static int size;
    public static int ccsize[];
    public static int corToId[][];

    public static int dfs(int i, int j, int c){
        if (i<0 || j<0 || i >=n || j >=m){
            return -1;
        }
        if(map[i][j] == '*'){
            return -1;
        }
        if(corToId[i][j] != 0){
            return corToId[i][j];
        }
        corToId[i][j]=c;
        ccsize[c]++;
        dfs(i+1, j, c);
        dfs(i-1, j, c);
        dfs(i, j+1, c);
        dfs(i, j-1, c);
        return c;
    }

    public static void main(String[] args) {
        corToId = new int[1010][1010];
        ccsize = new int[1001000];
        Scanner in = new Scanner(System.in);
        n = in.nextInt(); m = in.nextInt();
        map = new char[n][m];
        out = new char[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.next();
            for (int j = 0; j < m; j++) {
                map[i][j] = s.charAt(j);
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                dfs(i, j, idIndex);
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(map[i][j]=='*') {
                    Set<Integer> set = new HashSet<Integer>();
                    set.add(dfs(i - 1, j, 0));
                    set.add(dfs(i + 1, j, 0));
                    set.add(dfs(i, j - 1, 0));
                    set.add(dfs(i, j +1, 0));
                    int a = 1;
                    for (Integer x : set) {
                        if (x > -1) {
                            a+=ccsize[x];
                        }
                    }
                    out[i][j] = Character.forDigit(a%10, 10);
                }
                else{
                    out[i][j] = '.';
                }
            }
        }

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

        /*
        // for each * char, calculate connected components.
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(map[i][j] == '*'){
                    // perform dfs starting here
                    //map[i][j] = '.';
                    size = 0;
                    visited = new boolean[n][m];

                    out[i][j] = Character.forDigit(size%10, 10);
                    map[i][j] = '*';
                }
                else{
                    out[i][j]='.';
                }
            }
        }
        //System.out.println("end");
        for (int i = 0; i < n; i++) {
            String s= new String(out[i]);
            System.out.println(s);
        }
        */
    }
}


package EducationalRound5;

import java.util.Scanner;
import java.util.Stack;

/**
 * Created by baturayk on 12/01/16.
 You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle).
 Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they
 share a side.

 Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path
 of adjacent cells. It is a typical well-known definition of a connected component.

 For each impassable cell (x, y) imagine that it is an empty cell (all other cells remain unchanged) and find the size
 (the number of cells) of the connected component which contains (x, y). You should do it for each impassable cell
 independently.

 The answer should be printed as a matrix with n rows and m columns. The j-th symbol of the i-th row should be "." if
 the cell is empty at the start. Otherwise the j-th symbol of the i-th row should contain the only digit —- the answer
 modulo 10. The matrix should be printed without any spaces.

 To make your output faster it is recommended to build the output as an array of n strings having length m and print
 it as a sequence of lines. It will be much faster than writing character-by-character.

 As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use
 scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

 Input
 The first line contains two integers n, m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the field.

 Each of the next n lines contains m symbols: "." for empty cells, "*" for impassable cells.

 Output
 Print the answer as a matrix as described above. See the examples to precise the format of the output.
 *
 */
public class ER5_C {
    public static int n,m;
    public static char[][] map, out;
    public static boolean[][] visited;
    public static int size;
    public static void dfs(int x, int y){
        if(!(x<0 || x>=n || y<0 || y>=n)){
            if(visited[x][y] == false) {
                if (map[x][y] == '.') {
                    visited[x][y] = true;
                    size++;
                    dfs(x, y - 1);
                    dfs(x, y + 1);
                    dfs(x + 1, y);
                    dfs(x - 1, y);
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt(); m = in.nextInt();
        map = new char[n][m];
        out = new char[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.next();
            for (int j = 0; j < m; j++) {
                map[i][j] = s.charAt(j);
            }
        }

        // for each * char, calculate connected components.
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(map[i][j] == '*'){
                    // perform dfs starting here
                    map[i][j] = '.';
                    size = 0;
                    visited = new boolean[n][m];
                    dfs(i, j);
                    out[i][j] = Character.forDigit(size, 10);
                    map[i][j] = '*';
                }
                else{
                    out[i][j]='.';
                }
            }
        }
        //System.out.println("end");
        for (int i = 0; i < n; i++) {
            String s= new String(out[i]);
            System.out.println(s);
        }
    }
}


import java.util.Scanner;

/**
 * Created by baturayk on 12/01/16.
 You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle).
 Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they
 share a side.

 Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path
 of adjacent cells. It is a typical well-known definition of a connected component.

 For each impassable cell (x, y) imagine that it is an empty cell (all other cells remain unchanged) and find the size
 (the number of cells) of the connected component which contains (x, y). You should do it for each impassable cell
 independently.

 The answer should be printed as a matrix with n rows and m columns. The j-th symbol of the i-th row should be "." if
 the cell is empty at the start. Otherwise the j-th symbol of the i-th row should contain the only digit —- the answer
 modulo 10. The matrix should be printed without any spaces.

 To make your output faster it is recommended to build the output as an array of n strings having length m and print
 it as a sequence of lines. It will be much faster than writing character-by-character.

 As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use
 scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

 Input
 The first line contains two integers n, m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the field.

 Each of the next n lines contains m symbols: "." for empty cells, "*" for impassable cells.

 Output
 Print the answer as a matrix as described above. See the examples to precise the format of the output.
 *
 */
public class ER5_C {
    public static int n,m;
    public static char[][] map, out;
    public static boolean[][] visited;
    public static int size;
    public static void dfs(int x, int y){
        if(!(x<0 || x>=n || y<0 || y>=m)){
            if(visited[x][y] == false) {
                if (map[x][y] == '.') {
                    visited[x][y] = true;
                    size++;
                    dfs(x, y - 1);
                    dfs(x, y + 1);
                    dfs(x + 1, y);
                    dfs(x - 1, y);
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt(); m = in.nextInt();
        map = new char[n][m];
        out = new char[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.next();
            for (int j = 0; j < m; j++) {
                map[i][j] = s.charAt(j);
            }
        }

        // for each * char, calculate connected components.
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(map[i][j] == '*'){
                    // perform dfs starting here
                    map[i][j] = '.';
                    size = 0;
                    visited = new boolean[n][m];
                    dfs(i, j);
                    out[i][j] = Character.forDigit(size%10, 10);
                    map[i][j] = '*';
                }
                else{
                    out[i][j]='.';
                }
            }
        }
        //System.out.println("end");
        for (int i = 0; i < n; i++) {
            String s= new String(out[i]);
            System.out.println(s);
        }
    }
}


//package com.himanshu.practice.Aug.aug17;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * Created by himanshubhardwaj on 16/08/18.
 */
public class TheLabyrinth {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int m = Integer.parseInt(str[1]);

        Graph g = new Graph(n, m);
        str = new String[n];
        for (int i = 0; i < n; i++) {
            str[i] = br.readLine();
        }
        g.insert(str);
        str = g.getString();
        for (int i = 0; i < n; i++) {
            System.out.print(str[i]);
            if(i != (n-1)) {
                System.out.println();
            }
        }

    }
}

class Graph {
    int arr[][];
    int row;
    int column;
    static Map<Integer, ConnectedComponent> connectedComponentSize = new HashMap<>();

    public Graph(int r, int c) {
        this.row = r;
        this.column = c;
        arr = new int[row][column];
    }

    void insert(String[] str) {
        for (int i = 0; i < str.length; i++) {
            for (int j = 0; j < str[i].length(); j++) {
                arr[i][j] = (str[i].charAt(j) == '.') ? 0 : -1;
            }
        }
    }

    private void DFS() {
        int connectedCompnentIndex = 1;

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                if (arr[i][j] == 0) {
                    ConnectedComponent connectedComponent = new ConnectedComponent();
                    connectedComponent.index = connectedCompnentIndex;
                    DFSC(i, j, connectedComponent);
                    connectedCompnentIndex++;
                    connectedComponentSize.put(connectedComponent.index, connectedComponent);
                }
            }
        }

        //System.out.println(connectedComponentSize);
    }

    public String[] getString() {
        DFS();
        //System.out.println(connectedComponentSize);
        String str[] = new String[row];

        for (int i = 0; i < row; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < column; j++) {
                if (arr[i][j] == -1) {
                    sb.append(mergeConnectedClusters(i, j));
                } else {
                    sb.append('.');
                }

            }
            str[i] = sb.toString();
        }
        return str;
    }

    private char mergeConnectedClusters(int i, int j) {
        HashSet<ConnectedComponent> connectedComponentSet = new HashSet<>();
        getSize(i, j + 1, connectedComponentSet);
        getSize(i, j - 1, connectedComponentSet);
        getSize(i + 1, j, connectedComponentSet);
        getSize(i - 1, j, connectedComponentSet);

        int size = 1;
        for (ConnectedComponent c : connectedComponentSet) {
            size += c.size;
        }

        return (char) (size + '0');
    }

    private void getSize(int row, int column, HashSet<ConnectedComponent> connectedComponents) {
        if (row < 0 || row >= this.row || column < 0 || column >= this.column || arr[row][column] == -1) {
            return;
        }
        connectedComponents.add(connectedComponentSize.get(arr[row][column]));
    }

    private void DFSC(int i, int j, ConnectedComponent connectedComponent) {
        if (i < 0 || j < 0 || i >= row || j >= column || arr[i][j] != 0) {
            return;
        }
        arr[i][j] = connectedComponent.index;
        connectedComponent.size++;
        DFSC(i, j + 1, connectedComponent);
        DFSC(i, j - 1, connectedComponent);
        DFSC(i + 1, j, connectedComponent);
        DFSC(i - 1, j, connectedComponent);
    }
}

class ConnectedComponent {
    int index;
    int size;

    public boolean equals(Object o) {
        if (o == this) return true;
        if (!(o instanceof ConnectedComponent)) return false;
        final ConnectedComponent other = (ConnectedComponent) o;
        if (!other.canEqual((Object) this)) return false;
        if (this.index != other.index) return false;
        if (this.size != other.size) return false;
        return true;
    }

    public int hashCode() {
        int result = this.index;
        return result;
    }

    protected boolean canEqual(Object other) {
        return other instanceof ConnectedComponent;
    }
}


//package com.himanshu.practice.Aug.aug17;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * Created by himanshubhardwaj on 16/08/18.
 */
public class TheLabyrinth {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int m = Integer.parseInt(str[1]);

        Graph g = new Graph(n, m);
        str = new String[n];
        for (int i = 0; i < n; i++) {
            str[i] = br.readLine();
        }
        g.insert(str);
        str = g.getString();
        for (int i = 0; i < n; i++) {
            System.out.print(str[i]);
            if(i != (n-1)) {
                System.out.println();
            }
        }

    }
}

class Graph {
    int arr[][];
    int row;
    int column;
    static Map<Integer, ConnectedComponent> connectedComponentSize = new HashMap<>();

    public Graph(int r, int c) {
        this.row = r;
        this.column = c;
        arr = new int[row][column];
    }

    void insert(String[] str) {
        for (int i = 0; i < str.length; i++) {
            for (int j = 0; j < str[i].length(); j++) {
                arr[i][j] = (str[i].charAt(j) == '.') ? 0 : -1;
            }
        }
    }

    private void DFS() {
        int connectedCompnentIndex = 1;

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                if (arr[i][j] == 0) {
                    ConnectedComponent connectedComponent = new ConnectedComponent();
                    connectedComponent.index = connectedCompnentIndex;
                    DFSC(i, j, connectedComponent);
                    connectedCompnentIndex++;
                    connectedComponentSize.put(connectedComponent.index, connectedComponent);
                }
            }
        }

        //System.out.println(connectedComponentSize);
    }

    public String[] getString() {
        DFS();
        //System.out.println(connectedComponentSize);
        String str[] = new String[row];

        for (int i = 0; i < row; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < column; j++) {
                if (arr[i][j] == -1) {
                    sb.append(mergeConnectedClusters(i, j));
                } else {
                    sb.append('.');
                }

            }
            str[i] = sb.toString();
        }
        return str;
    }

    private char mergeConnectedClusters(int i, int j) {
        HashSet<ConnectedComponent> connectedComponentSet = new HashSet<>();
        getSize(i, j + 1, connectedComponentSet);
        getSize(i, j - 1, connectedComponentSet);
        getSize(i + 1, j, connectedComponentSet);
        getSize(i - 1, j, connectedComponentSet);

        int size = 1;
        for (ConnectedComponent c : connectedComponentSet) {
            size += c.size;
        }
        size = size%10;

        return (char) (size + '0');
    }

    private void getSize(int row, int column, HashSet<ConnectedComponent> connectedComponents) {
        if (row < 0 || row >= this.row || column < 0 || column >= this.column || arr[row][column] == -1) {
            return;
        }
        connectedComponents.add(connectedComponentSize.get(arr[row][column]));
    }

    private void DFSC(int i, int j, ConnectedComponent connectedComponent) {
        if (i < 0 || j < 0 || i >= row || j >= column || arr[i][j] != 0) {
            return;
        }
        arr[i][j] = connectedComponent.index;
        connectedComponent.size++;
        DFSC(i, j + 1, connectedComponent);
        DFSC(i, j - 1, connectedComponent);
        DFSC(i + 1, j, connectedComponent);
        DFSC(i - 1, j, connectedComponent);
    }
}

class ConnectedComponent {
    int index;
    int size;

    public boolean equals(Object o) {
        if (o == this) return true;
        if (!(o instanceof ConnectedComponent)) return false;
        final ConnectedComponent other = (ConnectedComponent) o;
        if (!other.canEqual((Object) this)) return false;
        if (this.index != other.index) return false;
        if (this.size != other.size) return false;
        return true;
    }

    public int hashCode() {
        int result = this.index;
        return result;
    }

    protected boolean canEqual(Object other) {
        return other instanceof ConnectedComponent;
    }
}


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

/**
 * Created by tdx on 3/10/16.
 */
public class CF616C {

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

    static class TaskX {
        static final int MAX = 1000;
        static int n, m;
        int[] dx = {1, -1, 0, 0};
        int[] dy = {0, 0, 1, -1};
        int[] cnt = new int [MAX + 5];
        int[][] region = new int[MAX + 5][MAX + 5];
        String[] mat = new String[MAX + 5];
        StringBuilder[] res = new StringBuilder[MAX + 5];
        int totalRegion = 0;

        void go(int x, int y) {
            for (int i = 0; i < 4; ++i) {
                int nx = dx[i] + x;
                int ny = dy[i] + y;

                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mat[nx].charAt(ny) == '.' && region[nx][ny] == 0) {
                    if (mat[x].charAt(y) == '*') {
                        totalRegion++;
                    } // else go to here by '.' adjacent, should same connected component

                    region[nx][ny] = totalRegion;
                    cnt[totalRegion]++;
                    go(nx, ny);
                }
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            for (int i = 0; i < n; ++i) {
                mat[i] = in.next();
            }

            for (int i = 0; i < n; ++i) {
                res[i] = new StringBuilder(mat[i]);

                for (int j = 0; j < m; ++j) {
                    if (mat[i].charAt(j) == '*') {
                        go(i, j);
                        int val = 0;
                        Set<Integer> regions = new HashSet<>();
                        for (int t = 0; t < 4; ++t) {
                            int ni = i + dx[t];
                            int nj = j + dy[t];

                            if (ni >= 0 && ni < n && 0 <= nj && nj < m && mat[ni].charAt(nj) == '.' && !regions.contains(region[ni][nj])) {
                                regions.add(region[ni][nj]);
                                val += cnt[region[ni][nj]];
                            }
                        }

                        res[i].setCharAt(j, (char) ('0' + (1 + val) % 10));
                    }
                }
                out.println(res[i]);
            }
        }
    }

    static class Pair {
        int x, y;
        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

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

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

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

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

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

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


import java.io.*;
import java.util.StringTokenizer;

/**
 * Created by tdx on 3/10/16.
 */
public class CF616C {

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

    static class TaskX {
        static final int MAX = 1000;
        static int n, m;
        int[] dx = {1, -1, 0, 0};
        int[] dy = {0, 0, 1, -1};
        boolean[][] visited = new boolean[MAX + 5][MAX + 5];
        String[] mat = new String[MAX + 5];
        StringBuilder[] res = new StringBuilder[MAX + 5];

        int go(int x, int y) {
            int value = 0;

            for (int i = 0; i < 4; ++i) {
                int nx = dx[i] + x;
                int ny = dy[i] + y;

                if (nx >= 0 && nx < n && ny >= 0 && ny < m && !visited[nx][ny] && mat[nx].charAt(ny) == '.') {
                    visited[nx][ny] = true;
                    value += 1 + go(nx, ny);
                    visited[nx][ny] = false;
                }
            }

            return value;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            for (int i = 0; i < n; ++i) {
                mat[i] = in.next();
            }

            for (int i = 0; i < n; ++i) {
                res[i] = new StringBuilder(mat[i]);

                for (int j = 0; j < m; ++j) {
                    if (mat[i].charAt(j) == '*') {
                        visited[i][j] = true;
                        int val = 1 + go(i, j);
                        res[i].setCharAt(j, (char) ('0' + val % 10));
                    }
                }

                out.println(res[i]);
            }
        }
    }

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

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

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

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

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

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


import java.io.*;
import java.util.ArrayDeque;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;

/**
 * Created by tdx on 3/10/16.
 */
public class CF616C {

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

    static class TaskX {
        static final int MAX = 1000;
        static int n, m;
        int[] dx = {1, -1, 0, 0};
        int[] dy = {0, 0, 1, -1};
        boolean[][] visited = new boolean[MAX + 5][MAX + 5];
        String[] mat = new String[MAX + 5];
        StringBuilder[] res = new StringBuilder[MAX + 5];
        Queue<Pair> queues = new ArrayDeque<>();

        int go(int x, int y) {
            queues.add(new Pair(x, y));

            int value = 0;
            for (int i = 0; i < 4; ++i) {
                int nx = dx[i] + x;
                int ny = dy[i] + y;

                if (nx >= 0 && nx < n && ny >= 0 && ny < m && !visited[nx][ny] && mat[nx].charAt(ny) == '.') {
                    visited[nx][ny] = true;
                    value += 1 + go(nx, ny);
                }
            }

            return value;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            for (int i = 0; i < n; ++i) {
                mat[i] = in.next();
            }

            for (int i = 0; i < n; ++i) {
                res[i] = new StringBuilder(mat[i]);

                for (int j = 0; j < m; ++j) {
                    if (mat[i].charAt(j) == '*') {
                        visited[i][j] = true;
                        int val = 1 + go(i, j);
                        res[i].setCharAt(j, (char) ('0' + val % 10));
                        while (!queues.isEmpty()) {
                            Pair p = queues.remove();
                            visited[p.x][p.y] = false;
                        }
                    }
                }

                out.println(res[i]);
            }
        }
    }

    static class Pair {
        int x, y;
        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

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

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

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

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

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

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


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

/**
 * Created by tdx on 3/10/16.
 */
public class CF616C {

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

    static class TaskX {
        static final int MAX = 1000;
        static int n, m;
        int[] dx = {1, -1, 0, 0};
        int[] dy = {0, 0, 1, -1};
        int[] cnt = new int [MAX * MAX + 5];
        int[][] region = new int[MAX + 5][MAX + 5];
        String[] mat = new String[MAX + 5];
        StringBuilder[] res = new StringBuilder[MAX + 5];
        int totalRegion = 0;

        void go(int x, int y) {
            for (int i = 0; i < 4; ++i) {
                int nx = dx[i] + x;
                int ny = dy[i] + y;

                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mat[nx].charAt(ny) == '.' && region[nx][ny] == 0) {
                    if (mat[x].charAt(y) == '*') {
                        totalRegion++;
                    } // else go to here by '.' adjacent, should same connected component

                    region[nx][ny] = totalRegion;
                    cnt[totalRegion]++;
                    go(nx, ny);
                }
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            for (int i = 0; i < n; ++i) {
                mat[i] = in.next();
            }

            for (int i = 0; i < n; ++i) {
                res[i] = new StringBuilder(mat[i]);

                for (int j = 0; j < m; ++j) {
                    if (mat[i].charAt(j) == '*') {
                        go(i, j);
                        int val = 0;
                        Set<Integer> regions = new HashSet<>();
                        for (int t = 0; t < 4; ++t) {
                            int ni = i + dx[t];
                            int nj = j + dy[t];

                            if (ni >= 0 && ni < n && 0 <= nj && nj < m && mat[ni].charAt(nj) == '.' && !regions.contains(region[ni][nj])) {
                                regions.add(region[ni][nj]);
                                val += cnt[region[ni][nj]];
                            }
                        }

                        res[i].setCharAt(j, (char) ('0' + (1 + val) % 10));
                    }
                }
                out.println(res[i]);
            }
        }
    }

    static class Pair {
        int x, y;
        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

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

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

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

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

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

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


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

@SuppressWarnings("unchecked")
public class P616C {

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

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

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

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

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

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

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

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

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (l[i][j] != 0) {
          f = new ArrayDeque();
          fill(i, j);
          ans.append(f.size() % 10);

          while (f.size() > 0) {
            int [] xy = f.pollFirst();
            l[xy[1]][xy[0]] = 0;
          }
          l[i][j] = -1;
        } else {
          ans.append('.');
        }
      }

      ans.append('\n');
    }

    println(ans);
  }

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

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

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

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


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

@SuppressWarnings("unchecked")
public class P616C {

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

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

  void fill(int x, int y) {
    l[y][x] = 1;
    f.add((x << SHIFT) | y);

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

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

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

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

    StringBuffer ans = new StringBuffer();

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

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

          k += 10;
        }
      }
    }

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

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

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

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

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

      ans.append('\n');
    }

    println(ans);
  }

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

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

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

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


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

@SuppressWarnings("unchecked")
public class P616C {

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

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

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

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

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

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

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

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

    public int elements() {
      return tail;
    }

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

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

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

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

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

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

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

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

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

          k += 10;
        }
      }
    }

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

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

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

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

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

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

      ans.append('\n');
    }

    println(ans);
  }

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

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

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

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