// Arup Guha
// 11/8/2009
// My Solution to 2009 SE Regional Problem E: Minesweeper

import java.util.*;
import java.io.*;

public class e {
	
	public static void main(String[] args) throws Exception {
		
		Scanner fin = new Scanner(new File("e.in"));
		
		// Get the input.
		int r = fin.nextInt();
		int c = fin.nextInt();
		
		while (r!=0 || c!=0) {
			
			char[][] board = new char[r][c];
			
			// Read in this board.
			for (int i=0; i<r; i++) {
				String line = fin.next();
				for (int j=0; j<c; j++)
					board[i][j] = line.charAt(j);
			}
			
			// Go through each row.
			for (int i=0; i<r; i++) {
			
				// Go through each column.
				for (int j=0; j<c; j++) {
					
					// If it's a bomb, just print it.
					if (board[i][j] == '*') 
						System.out.print('*');
					
					// If not, calculate # of adjacent bombs and print that.
					else
						System.out.print(numBombs(board,i,j));
				}
				
				// Go to the next line.
				System.out.println();
			}
			
			// Get next input case.
			r = fin.nextInt();
			c = fin.nextInt();
		}
		
		fin.close();
	}
	
	// Returns the number of bombs adjacent to square (row,col) in board.
	public static int numBombs(char[][] board, int row, int col) {
		
		int cnt = 0;
		
		// Go through 9 squares all around this one.
		for (int i=-1; i<=1; i++) {
			for (int j=-1; j<=1; j++) {
				
				// Don't get an out of bounds error!!!
				if (row+i<0 || row+i >= board.length) continue;
				else if (col+j<0 || col+j >= board[0].length) continue;
				
				// Add 1 to our count if this square's a bomb.
				if (board[row+i][col+j] == '*')
					cnt++;
			}
		}
		return cnt;
	}
}