# -*- coding: utf-8 -*-
import traceback


def main():
    def _check(y,x,h,w,_list,count):
        if x >= 0 and y >= 0 and x < w and y < h:
            if _list[y][x] == '#':
                count += 1

        return count


    h,w = map(int,raw_input().split())
    S = [list(raw_input()) for i in range(h)]
    ans = S

    for i,line in enumerate(S):
        for j,val in enumerate(line):
            count = 0
            if val == '.':
                count = _check(i-1,j-1,h,w,S,count)
                count = _check(i-1,j,h,w,S,count)
                count = _check(i-1,j+1,h,w,S,count)
                count = _check(i,j-1,h,w,S,count)
                count = _check(i,j,h,w,S,count)
                count = _check(i,j+1,h,w,S,count)
                count = _check(i+1,j-1,h,w,S,count)
                count = _check(i+1,j,h,w,S,count)
                count = _check(i+1,j+1,h,w,S,count)

                ans[i][j] = str(count)

    for line in ans:
        print ''.join(line)

main()
