Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim H As Integer = NextInt()
        Dim W As Integer = NextInt()
        Dim S As String() = New String(H - 1) {}
        For i As Integer = 0 To H - 1
            S(i) = NextString()
        Next
        Dim ans As Integer(,) = New Integer(H - 1, W - 1) {}

        For i As Integer = 0 To H - 1
            For j As Integer = 0 To W - 1
                If S(i)(j) = "#" Then
                    ans(i, j) = 9
                    For x As Integer = -1 To 1
                        For y As Integer = -1 To 1
                            If 0 <= i + y AndAlso i + y < H AndAlso
                                0 <= j + x AndAlso j + x < W Then
                                ans(i + y, j + x) += 1
                            End If
                        Next y
                    Next x
                End If
            Next j
        Next i

        For i As Integer = 0 To H - 1
            For j As Integer = 0 To W - 1
                If ans(i, j) >= 9 Then
                    Write("#")
                Else
                    Write(ans(i, j))
                End If
            Next
            WriteLine()
        Next
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module
