# -*- coding: utf-8 -*-
#from collections import Counter

H, W = map(int, raw_input().split())
s = []
for i in xrange(H):
    s.append(map(str, raw_input()))

for i in xrange(H):
    line = ''
    for j in xrange(W):
        if s[i][j] == '#':
            line+= '#'
        elif i == 0:
            if j == 0:
                line+= str(([s[i][j+1], s[i+1][j], s[i+1][j+1]]).count('#'))
            elif j == W:
                line+= str(([s[i][j-1], s[i+1][j], s[i-1][j-1]]).count('#'))
            else:
                line+= str((s[i][j+1], s[i+1][j], s[i+1][j+1], s[i][j-1], s[i-1][j-1]).count('#'))
        elif i == H:
            if j == 0:
                line+= str(([s[i-1][j], s[i][j+1], s[i-1][j+1]]).count('#'))
            elif j == W:
                line+= str(([s[i-1][j], s[i][j-1], s[i-1][j-1]]).count('#'))
            else:
                line+= str(([s[i-1][j], s[i][j+1], s[i-1][j+1], s[i][j-1], s[i-1][j-1]]).count('#'))
        else:
            if j == 0:
                line+= str(([s[i-1][j], s[i][j+1], s[i-1][j+1], s[i+1][j], s[i+1][j+1]]).count('#'))
            elif j == W:
                line+= str(([s[i-1][j], s[i][j-1], s[i-1][j-1], s[i+1][j], s[i+1][j-1]]).count('#'))
            else:
                line+= str(([s[i-1][j], s[i][j-1], s[i-1][j-1], s[i+1][j], s[i+1][j-1], s[i][j+1], s[i-1][j+1], s[i+1][j+1]]).count('#'))
    print line