#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    bool invalid = false;
    int x;
    int y;
    cin >> y >> x;
    string tabela[y][x];
    for (int i = 0; i < y; ++i)
    {
        string input;
        cin >> input;
        for (int j = 0; j < x; ++j)
        {
            tabela[i][j] = input[j];
        }
    }

    for (int i = 0; i < y; ++i)
    {
        for (int j = 0; j < x; ++j)
        {
            if (tabela[i][j] == "1" || tabela[i][j] == "2" || tabela[i][j] == "3" || tabela[i][j] == "4")
            {
                int maxSpotsFullfill = stoi(tabela[i][j]);
                int fullFilledSpots = 0;
                if (j - 1 >= 0)
                {
                    if (tabela[i][j - 1] == "." && (j - 2 >= 0 && tabela[i][j-2] != "0" || j - 2 < 0)
                    && (i - 1 >= 0 && tabela[j-1][i-1] != "0" || i - 1 < 0)
                    && (i + 1 < y && tabela[j-1][i+1] != "0" || i + 1 >= y) )
                    {
                        bool pass = true;
                        if (i - 1 >= 0)
                        {
                            for (int k = i - 1; k >= 0; --k)
                            {
                                if (tabela[k][j - 1] != ".")
                                {
                                    if (tabela[k][j - 1] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (i + 1 >= 0)
                        {
                            for (int k = i + 1; k < y; ++k)
                            {
                                if (tabela[k][j - 1] != ".")
                                {
                                    if (tabela[k][j - 1] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (j - 2 >= 0)
                        {
                            for (int k = j - 2; k >= 0; --k)
                            {
                                if (tabela[i][k] != ".")
                                {
                                    if (tabela[i][k] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (pass == true)
                        {
                            tabela[i][j-1] = "C";
                            ++fullFilledSpots;
                        }
                    }
                    else if (tabela[i][j - 1] == "C")
                    {
                        ++fullFilledSpots;
                    }
                }
                if (j + 1 < x && fullFilledSpots < maxSpotsFullfill)
                {

                    if (tabela[i][j + 1] == "." && (j + 2 < x && tabela[i][j+2] != "0" || j + 2 >= x)
                    && (i - 1 >= 0 && tabela[i-1][j+1] != "0" || i - 1 < 0)
                    && (i + 1 < y && tabela[i+1][j+1] != "0" || i + 1 >= y) )
                    {
                        bool pass = true;
                        if (i - 1 >= 0)
                        {
                            for (int k = i - 1; k >= 0; --k)
                            {
                                if (tabela[k][j + 1] != ".")
                                {
                                    if (tabela[k][j + 1] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (i + 1 >= 0)
                        {
                            for (int k = i + 1; k < y; ++k)
                            {
                                if (tabela[k][j + 1] != ".")
                                {
                                    if (tabela[k][j + 1] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (j + 2 < x)
                        {
                            for (int k = j + 2; k < x; ++k)
                            {
                                if (tabela[i][k] != ".")
                                {
                                    if (tabela[i][k] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (pass == true)
                        {
                            tabela[i][j+1] = "C";
                            ++fullFilledSpots;
                        }
                    }
                    else if (tabela[i][j + 1] == "C")
                    {
                        ++fullFilledSpots;
                    }
                }

                if (i - 1 >= 0 && fullFilledSpots < maxSpotsFullfill)
                {
                    if (tabela[i - 1][j] == "." && (i - 2 >= 0 && tabela[i - 2][j] != "0" || i - 2 < 0)
                    && (j - 1 >= 0 && tabela[j-1][i-1] != "0" || j - 1 < 0)
                    && (j + 1 < x && tabela[j+1][i-1] != "0" || j + 1 >= x) )
                    {
                        bool pass = true;
                        if (i - 2 >= 0)
                        {
                            for (int k = i - 2; k >= 0; --k)
                            {
                                if (tabela[k][j] != ".")
                                {
                                    if (tabela[k][j] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (j + 2 < x)
                        {
                            for (int k = j + 2; k < x - 1; ++k)
                            {
                                if (tabela[i - 1][k] != ".")
                                {
                                    if (tabela[i - 1][k] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (j - 2 >= 0)
                        {
                            for (int k = j - 2; k >= 0; --k)
                            {
                                if (tabela[i - 1][k] != ".")
                                {
                                    if (tabela[i - 1][k] == "C")
                                    {
                                        pass = false;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (pass == true)
                        {
                            tabela[i - 1][j] = "C";
                            ++fullFilledSpots;
                        }
                    }
                    else if (tabela[i][i - 1] == "C")
                    {
                        ++fullFilledSpots;
                    }
                }

                if (i + 1 < y && fullFilledSpots < maxSpotsFullfill)
                {
                    if (tabela[i + 1][j] == "." && (i + 2 < y && tabela[i + 2][j] != "0" || i + 2 >= y)
                    && (j - 1 >= 0 && tabela[j-1][i+1] != "0" || j - 1 < 0)
                    && (j + 1 < x && tabela[j+1][i+1] != "0" || j + 1 >= x) )
                    {
                        bool pass = true;
                        if (i + 2 >= 0)
                        {
                            for (int k = i + 2; k >= 0; ++k)
                            {
                                if (tabela[k][j] != ".")
                                {
                                    if (tabela[k][j] == "C")
                                    {
                                        pass = false;
                                        break;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (j + 2 < x)
                        {
                            for (int k = j + 2; k < x; ++k)
                            {
                                if (tabela[i + 1][k] != ".")
                                {
                                    if (tabela[i + 1][k] == "C")
                                    {
                                        pass = false;
                                        break;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (j - 2 >= 0)
                        {
                            for (int k = j - 2; k >= 0; --k)
                            {
                                if (tabela[i + 1][k] != ".")
                                {
                                    if (tabela[i + 1][k] == "C")
                                    {
                                        pass = false;
                                        break;
                                    }
                                    else{
                                        break;
                                    }
                                }
                            }
                        }
                        if (pass == true)
                        {
                            tabela[i + 1][j] = "C";
                            ++fullFilledSpots;
                        }
                    }
                    else if (tabela[i][i + 1] == "C")
                    {
                        ++fullFilledSpots;
                    }
                }

                if (fullFilledSpots != maxSpotsFullfill)
                {
                    invalid = true;
                    break;
                }

            }
        }
        if (invalid == true)
        {
            break;
        }
    }
    string tabela_copy[y][x];
    if (invalid == false)
    {
        //string tabela_copy[y][x];
        for (int i = 0; i < y; ++i)
        {
            for (int j = 0; j < x; ++j)
            {
                tabela_copy[i][j] = tabela[i][j];
            }
        }

        for (int i = 0; i < y; ++i)
        {
            for (int j = 0; j < x; ++j)
            {
                if (tabela_copy[i][j] == "C")
                {
                    for (int k = i - 1; k >= 0; --k)
                    {
                        if (tabela_copy[k][j] != "." && tabela_copy[k][j] != "N" )
                        {
                            break;
                        }
                        else
                        {
                            tabela_copy[k][j] = "N";
                        }
                    }

                    for (int k = i + 1; k < y; ++k)
                    {
                        if (tabela_copy[k][j] != "." && tabela_copy[k][j] != "N" )
                        {
                            break;
                        }
                        else
                        {
                            tabela_copy[k][j] = "N";
                        }
                    }

                    for (int k = j - 1; k >= 0; --k)
                    {
                        if (tabela_copy[i][k] != "." && tabela_copy[i][k] != "N" )
                        {
                            break;
                        }
                        else
                        {
                            tabela_copy[i][k] = "N";
                        }
                    }

                    for (int k = j + 1; k < x; ++k)
                    {
                        if (tabela_copy[i][k] != "." && tabela_copy[i][k] != "N" )
                        {
                            break;
                        }
                        else
                        {
                            tabela_copy[i][k] = "N";
                        }
                    }


                }
            }
        }

        int dotsDetected = 0;

        for (int i = 0; i < y; ++i)
        {
            for (int j = 0; j < x; ++j)
            {
                if (tabela_copy[i][j] == ".")
                {
                    ++dotsDetected;
                }
            }
        }

        while (dotsDetected > 0)
        {
            int passes = 0;
            int bestCoverageY = 0;
            int bestCoverageX = 0;
            int bestCoverageOverall = 0;
            for (int i = 0; i < y; ++i)
            {
                for (int j = 0; j < x; ++j)
                {
                    if (tabela_copy[i][j] == ".")
                    {
                        bool success = true;
                        if (i - 1 >= 0 && tabela_copy[i - 1][j] == "0")
                        {
                            success = false;
                        }

                        if (i + 1 < y && tabela_copy[i + 1][j] == "0")
                        {
                            success = false;
                        }

                        if (j - 1 < y && tabela_copy[i][j - 1] == "0")
                        {
                            success = false;
                        }

                        if (j + 1 < y && tabela_copy[i][j + 1] == "0")
                        {
                            success = false;
                        }

                        if (success == true)
                        {
                            int coverageGot = 0;
                            for (int k = i - 1; k >= 0; --k)
                            {
                                if (tabela_copy[k][j] != "." && tabela_copy[k][j] != "N" )
                                {
                                    break;
                                }
                                else
                                {
                                    ++coverageGot;
                                }
                            }

                            for (int k = i + 1; k < y; ++k)
                            {
                                if (tabela_copy[k][j] != "." && tabela_copy[k][j] != "N" )
                                {
                                    break;
                                }
                                else
                                {
                                    ++coverageGot;
                                }
                            }

                            for (int k = j - 1; k >= 0; --k)
                            {
                                if (tabela_copy[i][k] != "." && tabela_copy[i][k] != "N" )
                                {
                                    break;
                                }
                                else
                                {
                                    ++coverageGot;
                                }
                            }

                            for (int k = j + 1; k < x; ++k)
                            {
                                if (tabela_copy[i][k] != "." && tabela_copy[i][k] != "N" )
                                {
                                    break;
                                }
                                else
                                {
                                    ++coverageGot;
                                }
                            }

                            if (coverageGot > bestCoverageOverall)
                            {
                                bestCoverageOverall = coverageGot;
                                bestCoverageX = j;
                                bestCoverageY = i;
                            }

                            ++passes;
                        }

                    }
                }
            }

            if (passes == 0)
            {
                invalid = true;
                break;
            }

            tabela_copy[bestCoverageY][bestCoverageX] = "C";
            tabela[bestCoverageY][bestCoverageX] = "C";

            for (int k = bestCoverageY - 1; k >= 0; --k)
            {
                if (tabela_copy[k][bestCoverageX] != "." && tabela_copy[k][bestCoverageX] != "N" )
                {
                    break;
                }
                else
                {
                    tabela_copy[k][bestCoverageX] = "N";
                }
            }

            for (int k = bestCoverageY + 1; k < y; ++k)
            {
                if (tabela_copy[k][bestCoverageX] != "." && tabela_copy[k][bestCoverageX] != "N" )
                {
                    break;
                }
                else
                {
                    tabela_copy[k][bestCoverageX] = "N";
                }
            }

            for (int k = bestCoverageX - 1; k >= 0; --k)
            {
                if (tabela_copy[bestCoverageY][k] != "." && tabela_copy[bestCoverageY][k] != "N" )
                {
                    break;
                }
                else
                {
                    tabela_copy[bestCoverageY][k] = "N";
                }
            }

            for (int k = bestCoverageX + 1; k < x; ++k)
            {
                if (tabela_copy[bestCoverageY][k] != "." && tabela_copy[bestCoverageY][k] != "N" )
                {
                    break;
                }
                else
                {
                    tabela_copy[bestCoverageY][k] = "N";
                }
            }


            dotsDetected = 0;
            for (int i = 0; i < y; ++i)
            {
                for (int j = 0; j < x; ++j)
                {
                    if (tabela_copy[i][j] == ".")
                    {
                        ++dotsDetected;
                    }
                }
            }
        }




    }

    if (invalid == true)
    {
        cout << -1 << endl;
    }
    else{
        for (int i = 0; i < y; ++i)
        {
            for (int j = 0; j < x; ++j)
            {
                cout << tabela[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}