#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define forn(i, n) for (int i = 0; i < n; i++)
#define form(i, n, m) for (int i = n; i <= m; i++)
//
#define read(x) scanf("%d", &x)
#define write(x) printf("%d", &x)
#define read2(x, y) scanf("%d %d", &x, &y)
//
#define sqr(x) x*x
#define mp make_pair
#define pb push_back
#define pob pop_back
#define XX first
#define YY second
#define in insert
#define db long double
#define re return
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define sz size
#define rs resize
#define vec vector
#define all(a) a.begin(), a.end()
#define TASK "sum"   //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const str LN = "\n";
const double eps = 1e-7;
const double pi = acos(-1.0);
const int INF = (int)1e9 + 7;
const ll LINF = (ll)9e18 + 7;
bool in(int k, int x1, int x2) {re (k >= x1 && k <= x2);}

const int MAXN = 100007;

int n, m, k = 0;
char a[1007][1007], ans[1007][1007];
int was[1007][1007];

int bfs(int i, int j)
{
    int kk = 0;
    if (i - 1 >= 0 && a[i-1][j] != '*' && was[i-1][j] != k)
    {
        was[i-1][j] = k;
        kk++;
        kk += bfs(i - 1, j);
    }
    if (j - 1 >= 0 && a[i][j-1] != '*' && was[i][j-1] != k)
    {
        was[i][j-1] = k;
        kk++;
        kk += bfs(i, j - 1);
    }
    if (i + 1 < n && a[i + 1][j] != '*' && was[i+1][j] != k)
    {
        was[i+1][j] = k;
        kk++;
        kk += bfs(i + 1, j);
    }
    if (j + 1 < m && a[i][j + 1] != '*' && was[i][j + 1] != k)
    {
        was[i][j + 1] = k;
        kk++;
        kk += bfs(i, j + 1);
    }
    re kk;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("lock.in", "r", stdin); freopen("lock.out", "w", stdout);
    cin >> n >> m;
    forn(i, n)
        scanf("%s", a[i]);
    forn(i, n)
        forn(j, m)
            if (a[i][j] == '.')
            {
                ans[i][j] = '.';
            }
            else
            {
                k++;
                was[i][j] = k;
                ans[i][j] = ((bfs(i, j) + 1) % 10) + '0';
            }
    forn(i, n)
    {
        printf("%s", a[i]);
        cout << LN;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define forn(i, n) for (int i = 0; i < n; i++)
#define form(i, n, m) for (int i = n; i <= m; i++)
//
#define read(x) scanf("%d", &x)
#define write(x) printf("%d", &x)
#define read2(x, y) scanf("%d %d", &x, &y)
//
#define sqr(x) x*x
#define mp make_pair
#define pb push_back
#define pob pop_back
#define XX first
#define YY second
#define in insert
#define db long double
#define re return
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define sz size
#define rs resize
#define vec vector
#define all(a) a.begin(), a.end()
#define TASK "sum"   //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const str LN = "\n";
const double eps = 1e-7;
const double pi = acos(-1.0);
const int INF = (int)1e9 + 7;
const ll LINF = (ll)9e18 + 7;
bool in(int k, int x1, int x2) {re (k >= x1 && k <= x2);}

const int MAXN = 100007;

int n, m, k = 0;
char a[1007][1007], ans[1007][1007];
int was[1007][1007];

int bfs(int i, int j)
{
    int kk = 0;
    if (i - 1 >= 0 && a[i-1][j] != '*' && was[i-1][j] != k)
    {
        was[i-1][j] = k;
        kk++;
        kk += bfs(i - 1, j);
    }
    if (j - 1 >= 0 && a[i][j-1] != '*' && was[i][j-1] != k)
    {
        was[i][j-1] = k;
        kk++;
        kk += bfs(i, j - 1);
    }
    if (i + 1 < n && a[i + 1][j] != '*' && was[i+1][j] != k)
    {
        was[i+1][j] = k;
        kk++;
        kk += bfs(i + 1, j);
    }
    if (j + 1 < m && a[i][j + 1] != '*' && was[i][j + 1] != k)
    {
        was[i][j + 1] = k;
        kk++;
        kk += bfs(i, j + 1);
    }
    re kk;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("lock.in", "r", stdin); freopen("lock.out", "w", stdout);
    cin >> n >> m;
    forn(i, n)
        forn(j, m)
            cin >> a[i][j];
    forn(i, n)
        forn(j, m)
            if (a[i][j] == '.')
            {
                ans[i][j] = '.';
            }
            else
            {
                k++;
                was[i][j] = k;
                ans[i][j] = ((bfs(i, j) + 1) % 10) + '0';
            }
    forn(i, n)
    {
        forn(j, m)
            cout << ans[i][j];
        cout << LN;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define forn(i, n) for (int i = 0; i < n; i++)
#define form(i, n, m) for (int i = n; i <= m; i++)
//
#define read(x) scanf("%d", &x)
#define write(x) printf("%d", &x)
#define read2(x, y) scanf("%d %d", &x, &y)
//
#define sqr(x) x*x
#define mp make_pair
#define pb push_back
#define pob pop_back
#define XX first
#define YY second
#define in insert
#define db long double
#define re return
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define sz size
#define rs resize
#define vec vector
#define all(a) a.begin(), a.end()
#define TASK "sum"   //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const str LN = "\n";
const double eps = 1e-7;
const double pi = acos(-1.0);
const int INF = (int)1e9 + 7;
const ll LINF = (ll)9e18 + 7;
bool in(int k, int x1, int x2) {re (k >= x1 && k <= x2);}

const int MAXN = 100007;

int n, m, k = 1, kk = 1;
char a[1007][1007];
int t[1000007];
int was[1007][1007];
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};

void bfs(int x,int y)
{
    kk++;
    was[x][y] = k;
    forn(i, 4)
    if (x + dx[i] > -1 && x + dx[i] < n && y + dy[i] > -1 && y + dy[i] < m && a[x + dx[i]][y + dy[i]] != '*' && was[x + dx[i]][y + dy[i]] == 0)
    {
        bfs(x + dx[i], y + dy[i]);
    }
}

int main()
{
  /*  ios_base::sync_with_stdio(0);
    cin.tie(NULL);  */
    //freopen("lock.in", "r", stdin); freopen("lock.out", "w", stdout);
    cin >> n >> m;
    forn(i, n)
        scanf("%s", a[i]);
    forn(i, n)
        forn(j, m)
            if (was[i][j] == 0 && a[i][j] != '*')
            {
                kk = 0;
                bfs(i, j);
                t[k] = kk;
                k++;
            }
    forn(i, n)
    {
        forn(j, m)
            if (a[i][j] == '.')
            {
                cout << a[i][j];
            }
            else
            {
                cout << (t[was[i-1][j]] + t[was[i+1][j]] + t[was[i][j-1]] + t[was[i][j+1]] + 1) % 10;
            }
        cout << LN;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define forn(i, n) for (int i = 0; i < n; i++)
#define form(i, n, m) for (int i = n; i <= m; i++)
//
#define read(x) scanf("%d", &x)
#define write(x) printf("%d", &x)
#define read2(x, y) scanf("%d %d", &x, &y)
//
#define sqr(x) x*x
#define mp make_pair
#define pb push_back
#define pob pop_back
#define XX first
#define YY second
#define in insert
#define db long double
#define re return
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define sz size
#define rs resize
#define vec vector
#define all(a) a.begin(), a.end()
#define TASK "sum"   //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const str LN = "\n";
const double eps = 1e-7;
const double pi = acos(-1.0);
const int INF = (int)1e9 + 7;
const ll LINF = (ll)9e18 + 7;
bool in(int k, int x1, int x2) {re (k >= x1 && k <= x2);}

const int MAXN = 100007;

int n, m, k = 0;
char a[1007][1007], ans[1007][1007];
int was[1007][1007];

int bfs(int i, int j)
{
    int kk = 0;
    if (i - 1 >= 0 && a[i-1][j] != '*' && was[i-1][j] != k)
    {
        was[i-1][j] = k;
        kk++;
        kk += bfs(i - 1, j);
    }
    if (j - 1 >= 0 && a[i][j-1] != '*' && was[i][j-1] != k)
    {
        was[i][j-1] = k;
        kk++;
        kk += bfs(i, j - 1);
    }
    if (i + 1 < n && a[i + 1][j] != '*' && was[i+1][j] != k)
    {
        was[i+1][j] = k;
        kk++;
        kk += bfs(i + 1, j);
    }
    if (j + 1 < m && a[i][j + 1] != '*' && was[i][j + 1] != k)
    {
        was[i][j + 1] = k;
        kk++;
        kk += bfs(i, j + 1);
    }
    re kk;
}

int main()
{
  /*  ios_base::sync_with_stdio(0);
    cin.tie(NULL);  */
    //freopen("lock.in", "r", stdin); freopen("lock.out", "w", stdout);
    cin >> n >> m;
    forn(i, n)
        scanf("%s", a[i]);

    forn(i, n)
    {
        forn(j, m)
            if (a[i][j] == '.')
            {
                cout << ".";
            }
            else
            {
                k++;
                was[i][j] = k;
                cout << ((bfs(i, j) + 1) % 10);
            }
        cout << LN;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 1005;

char arr[MAX][MAX];
bool v[MAX][MAX];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int cc[MAX][MAX];
int sze[MAX];
int n, m;
int ccc = 0;
bool ok(int a, int b) {
    return (0<=a && 0<=b && a<n && b<m);
}

void dfs(int a, int b) {
    cc[a][b] = ccc;
    sze[ccc]++;
    v[a][b] = true;
    F0R(i, 4) {
        int newa = a + dx[i];
        int newb = b + dy[i];
        if (!ok(newa, newb)) { continue; }
        if (v[newa][newb]) { continue; }
        if (arr[newa][newb] == '*') { continue; }
        dfs(newa, newb);
    }
}

int main() {
    cin >> n >> m;
    F0R(i, n) {
        F0R(j, m) {
            cin >> arr[i][j];
        }
    }
    F0R(i, n) { F0R(j, m) {
        if (!v[i][j] && arr[i][j] == '.') { ccc++; dfs(i, j); }
    }}
    F0R(i, n) { F0R(j, m) {
        if (arr[i][j] == '.') { cout << '.'; }
        else {
            int tot = 0;
            vi ccs;
            map<int, bool> taken;
            F0R(k, 4) {
                int ni = i+dx[k];
                int nj = j+dy[k];
                if (!ok(ni, nj)) { continue; }
                if (cc[ni][nj] != 0) {
                    ccs.pb(cc[ni][nj]);
                }
            }
            for (int k : ccs) {
                if (!taken[k]) { taken[k] = true; tot += sze[k]; }
            }
            cout << (tot + 1)%10;
        }
    }
    cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 1005;

char arr[MAX][MAX];
bool v[MAX][MAX];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int cc[MAX][MAX];
int sze[MAX];
int n, m;
int ccc = 0;
bool ok(int a, int b) {
    return (0<=a && 0<=b && a<n && b<m);
}

void dfs(int a, int b) {
    cc[a][b] = ccc;
    sze[ccc]++;
    v[a][b] = true;
    F0R(i, 4) {
        int newa = a + dx[i];
        int newb = b + dy[i];
        if (!ok(newa, newb)) { continue; }
        if (v[newa][newb]) { continue; }
        if (arr[newa][newb] == '*') { continue; }
        dfs(newa, newb);
    }
}

int main() {
    cin >> n >> m;
    F0R(i, n) {
        F0R(j, m) {
            cin >> arr[i][j];
        }
    }
    F0R(i, n) { F0R(j, m) {
        if (!v[i][j] && arr[i][j] == '.') { ccc++; dfs(i, j); }
    }}
    F0R(i, n) { F0R(j, m) {
        if (arr[i][j] == '.') { cout << '.'; }
        else {
            int tot = 0;
            vi ccs;
            set<int> takens;
            F0R(k, 4) {
                int ni = i+dx[k];
                int nj = j+dy[k];
                if (!ok(ni, nj)) { continue; }
                if (cc[ni][nj] != 0) {
                    takens.insert(cc[ni][nj]);
                }
            }
            for (int k : takens) {
                tot += sze[k];
            }
            cout << (tot + 1)%10;
        }
    }
    cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 1005;

char arr[MAX][MAX];
bool v[MAX][MAX];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int cc[MAX][MAX];
int sze[MAX];
int n, m;
int ccc = 0;
bool ok(int a, int b) {
    return (0<=a && 0<=b && a<n && b<m);
}

void dfs(int a, int b) {
    cc[a][b] = ccc;
    sze[ccc]++;
    v[a][b] = true;
    F0R(i, 4) {
        int newa = a + dx[i];
        int newb = b + dy[i];
        if (!ok(newa, newb)) { continue; }
        if (v[newa][newb]) { continue; }
        if (arr[newa][newb] == '*') { continue; }
        dfs(newa, newb);
    }
}

int main() {
    cin >> n >> m;
    F0R(i, n) {
        F0R(j, m) {
            cin >> arr[i][j];
        }
    }
    F0R(i, n) { F0R(j, m) {
        if (!v[i][j] && arr[i][j] == '.') { ccc++; dfs(i, j); }
    }}
    F0R(i, n) { F0R(j, m) {
        if (arr[i][j] == '.') { cout << '.'; }
        else {
            int tot = 0;
            vi ccs;
            map<int, bool> taken;
            F0R(k, 4) {
                int ni = i+dx[k];
                int nj = j+dy[k];
                if (cc[ni][nj] != 0) {
                    ccs.pb(cc[ni][nj]);
                }
            }
            for (int k : ccs) {
                if (!taken[k]) { taken[k] = true; tot += sze[k]; }
            }
            cout << tot + 1;
        }
    }
    cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 1005;

char arr[MAX][MAX];
bool v[MAX][MAX];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int cc[MAX][MAX];
int sze[MAX];
int n, m;
int ccc = 0;
bool ok(int a, int b) {
    return (0<=a && 0<=b && a<n && b<m);
}

void dfs(int a, int b, int c) {
    cc[a][b] = c;
    sze[c]++;
    v[a][b] = true;
    F0R(i, 4) {
        int newa = a + dx[i];
        int newb = b + dy[i];
        if (!ok(newa, newb)) { continue; }
        if (v[newa][newb]) { continue; }
        if (arr[newa][newb] == '*') { continue; }
        dfs(newa, newb, c);
    }
}

int main() {
    cin >> n >> m;
    F0R(i, n) {
        F0R(j, m) {
            cin >> arr[i][j];
        }
    }
    int ct = 1;
    F0R(i, n) { F0R(j, m) {
        if (!v[i][j] && arr[i][j] == '.') { dfs(i, j, ct); ct++; }
    }}
    F0R(i, n) { F0R(j, m) {
        if (arr[i][j] == '.') { cout << '.'; }
        else {
            int tot = 0;
            vi ccs;
            set<int> takens;
            F0R(k, 4) {
                int ni = i+dx[k];
                int nj = j+dy[k];
                if (!ok(ni, nj)) { continue; }
                if (cc[ni][nj] != 0) {
                    takens.insert(cc[ni][nj]);
                }
            }
            for (int k : takens) {
                tot += sze[k];
            }
            cout << (tot + 1)%10;
        }
    }
    cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 1005;

char arr[MAX][MAX];
bool v[MAX][MAX];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int cc[MAX][MAX];
int sze[MAX];
int n, m;
int ccc = 0;
bool ok(int a, int b) {
    return (0<=a && 0<=b && a<n && b<m);
}

void dfs(int a, int b, int c) {
    cc[a][b] = c;
    sze[c]++;
    v[a][b] = true;
    F0R(i, 4) {
        int newa = a + dx[i];
        int newb = b + dy[i];
        if (!ok(newa, newb)) { continue; }
        if (v[newa][newb]) { continue; }
        if (arr[newa][newb] == '*') { continue; }
        dfs(newa, newb, c);
    }
}

int main() {
    cin >> n >> m;
    F0R(i, n) {
        F0R(j, m) {
            cin >> arr[i][j];
        }
    }
    int ct = 1;
    F0R(i, n) { F0R(j, m) {
        if (!v[i][j] && arr[i][j] == '.') { dfs(i, j, ct); ct++; }
    }}
    F0R(i, n) { F0R(j, m) {
        if (arr[i][j] == '.') { cout << '.'; }
        else {
            int tot = 0;
            vi ccs;
            set<int> takens;
            F0R(k, 4) {
                int ni = i+dx[k];
                int nj = j+dy[k];
                if (!ok(ni, nj)) { continue; }
                takens.insert(cc[ni][nj]);
            }
            for (int k : takens) {
                tot += sze[k];
            }
            cout << (tot + 1)%10;
        }
    }
    cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 1005;

char arr[MAX][MAX];
bool v[MAX][MAX];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int cc[MAX][MAX];
int sze[MAX*MAX];
int n, m;
int ccc = 0;
bool ok(int a, int b) {
    return (0<=a && 0<=b && a<n && b<m);
}

void dfs(int a, int b) {
    cc[a][b] = ccc;
    sze[ccc]++;
    v[a][b] = true;
    F0R(i, 4) {
        int newa = a + dx[i];
        int newb = b + dy[i];
        if (!ok(newa, newb)) { continue; }
        if (v[newa][newb]) { continue; }
        if (arr[newa][newb] == '*') { continue; }
        dfs(newa, newb);
    }
}

int main() {
    cin >> n >> m;
    F0R(i, n) {
        F0R(j, m) {
            cin >> arr[i][j];
        }
    }
    F0R(i, n) { F0R(j, m) {
        if (!v[i][j] && arr[i][j] == '.') { ccc++; dfs(i, j); }
    }}
    F0R(i, n) { F0R(j, m) {
        if (arr[i][j] == '.') { cout << '.'; }
        else {
            int tot = 0;
            vi ccs;
            map<int, bool> taken;
            F0R(k, 4) {
                int ni = i+dx[k];
                int nj = j+dy[k];
                if (!ok(ni, nj)) { continue; }
                if (cc[ni][nj] != 0) {
                    ccs.pb(cc[ni][nj]);
                }
            }
            for (int k : ccs) {
                if (!taken[k]) { taken[k] = true; tot += sze[k]; }
            }
            cout << (tot + 1)%10;
        }
    }
    cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 1005;

char arr[MAX][MAX];
bool v[MAX][MAX];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int cc[MAX][MAX];
int sze[MAX];
int n, m;
int ccc = 0;
bool ok(int a, int b) {
    return (0<=a && 0<=b && a<n && b<m);
}

void dfs(int a, int b) {
    cc[a][b] = ccc;
    sze[ccc]++;
    v[a][b] = true;
    F0R(i, 4) {
        int newa = a + dx[i];
        int newb = b + dy[i];
        if (!ok(newa, newb)) { continue; }
        if (v[newa][newb]) { continue; }
        if (arr[newa][newb] == '*') { continue; }
        dfs(newa, newb);
    }
}

int main() {
    cin >> n >> m;
    F0R(i, n) {
        F0R(j, m) {
            cin >> arr[i][j];
        }
    }
    F0R(i, n) { F0R(j, m) {
        if (!v[i][j] && arr[i][j] == '.') { ccc++; dfs(i, j); }
    }}
    F0R(i, n) { F0R(j, m) {
        if (arr[i][j] == '.') { cout << '.'; }
        else {
            int tot = 0;
            vi ccs;
            map<int, bool> taken;
            F0R(k, 4) {
                int ni = i+dx[k];
                int nj = j+dy[k];
                if (!ok(ni, nj)) { continue; }
                if (cc[ni][nj] != 0) {
                    ccs.pb(cc[ni][nj]);
                }
            }
            for (int k : ccs) {
                if (!taken[k]) { taken[k] = true; tot += sze[k]; }
            }
            cout << tot + 1;
        }
    }
    cout << endl;
    }
}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

ll cnt[400000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;
                            dbg ( tag[i][j] );

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int j = 0; j < 4; ++j ) {

                    int vx = ux + dx[j], vy = uy + dy[j];

                    if ( vx < 0 || vy < 0 || vx >= n || vy >= m ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

ll cnt[100000000];
ll tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int i = 0; i < 4; ++i ) {

                    int vx = ux + dx[i], vy = uy + dy[i];

                    if ( vx < 0 || vy <0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

ll cnt[400000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;
                            dbg ( tag[i][j] );

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int j = 0; j < 4; ++j ) {

                    int vx = ux + dx[j], vy = uy + dy[j];

                    if ( vx < 0 || vy < 0 || vx >= n || vy >= m || grid[vx][vy] != '.' ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

int cnt[100000000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int i = 0; i < 4; ++i ) {

                    int vx = ux + dx[i], vy = uy + dy[i];

                    if ( vx < 0 || vy <0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

ll cnt[400000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;
                            dbg ( tag[i][j] );

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int j = 0; j < 4; ++j ) {

                    int vx = ux + dx[j], vy = uy + dy[j];

                    if ( vx < 0 || vy < 0 || vx >= n || vy >= m ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

ll cnt[400000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;
                            dbg ( tag[i][j] );

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int j = 0; j < 4; ++j ) {

                    int vx = ux + dx[j], vy = uy + dy[j];

                    if ( vx < 0 || vy < 0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

int cnt[50000000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int i = 0; i < 4; ++i ) {

                    int vx = ux + dx[i], vy = uy + dy[i];

                    if ( vx < 0 || vy <0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

ll cnt[50000000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int j = 0; j < 4; ++i ) {

                    int vx = ux + dx[j], vy = uy + dy[j];

                    if ( vx < 0 || vy < 0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

int cnt[50000000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int j = 0; j < 4; ++i ) {

                    int vx = ux + dx[j], vy = uy + dy[j];

                    if ( vx < 0 || vy < 0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

int cnt[50000000];
int tag[1010][1010];
char grid[1010][1010];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int i = 0; i < 4; ++i ) {

                    int vx = ux + dx[i], vy = uy + dy[i];

                    if ( vx < 0 || vy <0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

ll cnt[400000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;
                            dbg ( tag[i][j] );

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int j = 0; j < 4; ++j ) {

                    int vx = ux + dx[j], vy = uy + dy[j];

                    if ( vx < 0 || vy < 0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

int cnt[80000000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int i = 0; i < 4; ++i ) {

                    int vx = ux + dx[i], vy = uy + dy[i];

                    if ( vx < 0 || vy <0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
//#define yamin
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define EPS 1e9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif

int cnt[50000000];
int tag[1000][1000];
char grid[1000][1000];

int main () {

    //freopen ( "input.txt", "r", stdin );

    int n, m;
    scanf ( "%d%d", &n, &m );

    vii star;

    getchar();

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    scanf ( "%c", &grid[i][j] );

                    if ( grid[i][j] == '*' ) star.PB ( pii ( i, j ) );

            }

            getchar();

    }

    int c = 0;

    for ( int i = 0; i < n; ++i ) {

            for ( int j = 0; j < m; ++j ) {

                    if ( !tag[i][j] && grid[i][j] == '.' ) {

                            tag[i][j] = ++c;

                            dbg ( i, j, c );

                            queue < pii > bfs;

                            bfs.push ( pii ( i, j ) );

                            while ( !bfs.empty() ) {

                                    pii temp = bfs.front();
                                    bfs.pop();
                                    cnt[c]++;

                                    int ux = temp.F, uy = temp.S;
                                    dbg ( ux, uy );

                                    for ( int k = 0; k < 4; ++k ) {

                                            int vx = ux + dx[k], vy = uy + dy[k];

                                            if ( vx >= 0 && vy >= 0 && vx < n && vy < m && !tag[vx][vy] && grid[vx][vy] == '.' ) {

                                                    tag[vx][vy] = c;
                                                    bfs.push ( pii ( vx, vy ) );

                                            }

                                    }

                            }

                    }

            }

    }

    int len = star.size();

    for ( int i = 0; i < len; ++i ) {

            set < int > exist;

            int ux = star[i].F, uy = star[i].S;
            ll ans = 1;

            for ( int j = 0; j < 4; ++j ) {

                    int vx = ux + dx[j], vy = uy + dy[j];

                    if ( vx < 0 || vy < 0 || vx >= n || vy >= m || grid[vx][vy] != '.' || exist.find(tag[vx][vy]) != exist.end() ) continue;

                    exist.insert ( tag[vx][vy] );

                    ans += cnt[tag[vx][vy]];

            }

            ans %= 10;
            grid[ux][uy] = '0' + ans;

    }

    for ( int i = 0; i < n; ++i ) {

            printf ( "%s\n", grid[i] );

    }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define fi freopen("input.txt","r",stdin)
#define fo freopen("output.txt","w",stdout)
#define l(s) int(s.size())
#define pb push_back
char s[1005][1005];
int cc[1005][1005],c[1010101],n,m;
int dfs(int i,int j,int z)
{
	if(i<0||j<0||i>=n||j>=m) return -1;
	if(s[i][j]=='*') return -1;
	if(cc[i][j]) return cc[i][j];
	cc[i][j]=z;
	c[z]++;
	dfs(i+1,j,z);
	dfs(i-1,j,z);
	dfs(i,j+1,z);
	dfs(1,j-1,z);
	return z;
}
int main()
{
	int z=1;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			dfs(i,j,z++);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(s[i][j]=='*')
			{
				set<int> f;
				f.insert(dfs(i-1,j,0));
				f.insert(dfs(i+1,j,0));
				f.insert(dfs(i,j-1,0));
				f.insert(dfs(i,j+1,0));
				int ans=1;
				for(int x:f)
				{
					if(x>-1)
					{
						ans+=c[x];
					}
					cout<<char('0'+(ans%10));
				}
			}
			else
				cout<<'.';
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s[1005];
int vis[1005][1005],c[1000005],n,m;
int dfs(int i,int j,int z)
{
    if(i<0||j<0||i>=n||j>=m) return -1;
    if(s[i][j]=='*') return -1;
    if(vis[i][j]) return vis[i][j];
    vis[i][j]=z;
    c[z]++;
    dfs(i+1,j,z);
    dfs(i-1,j,z);
    dfs(i,j+1,z);
    dfs(i,j-1,z);
    return z;
}
int main()
{
    int i2=1;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>s[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            dfs(i,j,i2++);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j]=='*')
            {
                set<int> f;
                f.insert(dfs(i-1,j,0));
                f.insert(dfs(i+1,j,0));
                f.insert(dfs(i,j-1,0));
                f.insert(dfs(i,j+1,0));
                int ans=1;
                for(set<int>::iterator x=f.begin();x!=f.end();x++)
                {
                    if(*x>-1)
                    {
                        ans+=c[*x];
                    }
                }
				cout<<ans%10;
            }
            else
                cout<<'.';
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
string s[1005];
int cc[1005][1005],ccl[1010101],n,m;
int dfs(int i,int j,int c)
{
    if(i<0||j<0||i>=n||j>=m) return -1;
    if(s[i][j]=='*') return -1;
    if(cc[i][j]) return cc[i][j];
    cc[i][j]=c;
    ccl[c]++;
    dfs(i+1,j,c);
    dfs(i-1,j,c);
    dfs(i,j+1,c);
    dfs(i,j-1,c);
    return c;
}
int main()
{
    int i2=1;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>s[i];
    for(int i=0;i<n;i++)
        for(int ii=0;ii<m;ii++)
            dfs(i,ii,i2++);
    for(int i=0;i<n;i++)
    {
        for(int ii=0;ii<m;ii++)
        {
            if(s[i][ii]=='*')
            {
                set<int> f;
                f.insert(dfs(i-1,ii,0));
                f.insert(dfs(i+1,ii,0));
                f.insert(dfs(i,ii-1,0));
                f.insert(dfs(i,ii+1,0));
                int ans=1;
                for(set<int>::iterator x=f.begin();x!=f.end();x++)
                {
                    if(*x>-1)
                    {
                        ans+=ccl[*x];
                    }
                }
				cout<<ans%10;
            }
            else
                cout<<'.';
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
string s[1005];
int vis[1005][1005],c[1000005],n,m;
int dfs(int i,int j,int z)
{
    if(i<0||j<0||i>=n||j>=m) return -1;
    if(s[i][j]=='*') return -1;
    if(vis[i][j]) return vis[i][j];
    vis[i][j]=z;
    c[z]++;
    dfs(i+1,j,z);
    dfs(i-1,j,z);
    dfs(i,j+1,z);
    dfs(i,j-1,z);
    return z;
}
int main()
{
    int one=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>s[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            dfs(i,j,++one);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j]=='*')
            {
                set<int> f;
                f.insert(dfs(i-1,j,0));
                f.insert(dfs(i+1,j,0));
                f.insert(dfs(i,j-1,0));
                f.insert(dfs(i,j+1,0));
                int ans=1;
                for(set<int>::iterator x=f.begin();x!=f.end();x++)
                {
                    if(*x>-1)
                    {
                        ans+=c[*x];
                    }
                }
				cout<<ans%10;
            }
            else
                cout<<'.';
        }
        cout<<endl;
    }
}


#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<fstream>
using namespace std;
struct Node
{
	int i, j, k;
};
int A[1024][1024];
int D[1024][1024];
Node e;
queue<Node> q;
int v[1024],N,M;
int dx[4] = {1,0,-1,0};
int dy[4] = { 0,-1,0,1 };

bool isInside(int i, int j)
{
	return i >= 1 && i <= N && j >= 1 && j <= M;
}
void Lee(int i,int j,int f)
{
	e.i = i;
	e.j = j;
	e.k = f;
	D[i][j] = f;
	q.push(e);

	while (q.size())
	{
		Node z;
		e = q.front();
		for (int k = 0;k < 4;++k)
			if (isInside(e.i + dx[k], e.j + dy[k]) && A[e.i + dx[k]][e.j + dy[k]]!=-1 && D[e.i + dx[k]][e.j + dy[k]]== 0)
			{
				++v[f];
				A[e.i + dx[k]][e.j + dy[k]] = A[e.i][e.j] + 1;
				D[e.i + dx[k]][e.j + dy[k]] = f;
				z.i = e.i + dx[k];
				z.j = e.j + dy[k];
				z.k = f;
				q.push(z);
			}
		q.pop();
	}
}

int main()
{
	cin >> N >> M;
	char c;
	for (int i = 1;i <= N;++i)
		for (int j = 1;j <= M;++j)
		{
			cin >> c;
			if (c == '*')
				A[i][j] = -1;
		}
	int k = 1;
	for (int i = 1;i <= N;++i)
		for (int j = 1;j <= M;++j)
			if (A[i][j] == 0 && D[i][j] == 0)
			{
				Lee(i, j, k);
				++k;
			}
	int s = 0,pa,ok=1;
	vector<int> la;
	for (int i = 1;i <= N;++i)
	{
		for (int j = 1;j <= M;++j)
		{
			if (A[i][j] == -1)
			{
				s = 1;
				for (int k = 0;k < 4;++k)
				{
					if (isInside(i + dx[k], j + dy[k]) && A[i + dx[k]][j + dy[k]] != -1)
					{
						ok = 0;
						for (pa = 0;pa < la.size();++pa)
							if (la[pa] == D[i + dx[k]][j + dy[k]])
								ok = 1;
						if (!ok)
						{
							s = s + v[D[i + dx[k]][j + dy[k]]] + 1;
							la.push_back(D[i + dx[k]][j + dy[k]]);
						}

					}
				}
				cout << s % 10;
				la.clear();
			}
			else
				cout << ".";
		}
		cout << '\n';
	}
	return 0;

}


#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<fstream>
using namespace std;
struct Node
{
	int i, j, k;
};
int A[1024][1024];
int D[1024][1024];
Node e;
queue<Node> q;
int v[1024],N,M;
int dx[4] = {1,0,-1,0};
int dy[4] = { 0,-1,0,1 };

bool isInside(int i, int j)
{
	return i >= 1 && i <= N && j >= 1 && j <= M;
}
void Lee(int i,int j,int f)
{
	e.i = i;
	e.j = j;
	e.k = f;
	D[i][j] = f;
	q.push(e);

	while (q.size())
	{
		Node z;
		e = q.front();
		for (int k = 0;k < 4;++k)
			if (isInside(e.i + dx[k], e.j + dy[k]) && A[e.i + dx[k]][e.j + dy[k]]!=-1 && D[e.i + dx[k]][e.j + dy[k]]== 0)
			{
				++v[f];
				A[e.i + dx[k]][e.j + dy[k]] = A[e.i][e.j] + 1;
				D[e.i + dx[k]][e.j + dy[k]] = f;
				z.i = e.i + dx[k];
				z.j = e.j + dy[k];
				z.k = f;
				q.push(z);
			}
		q.pop();
	}
}

int main()
{
	cin >> N >> M;
	char c;
	for (int i = 1;i <= N;++i)
		for (int j = 1;j <= M;++j)
		{
			cin >> c;
			if (c == '*')
				A[i][j] = -1;
		}
	int k = 1;
	for (int i = 1;i <= N;++i)
		for (int j = 1;j <= M;++j)
			if (A[i][j] == 0 && D[i][j] == 0)
			{
				Lee(i, j, k);
				++k;
			}
	int s = 0,pa,ok=1;
	vector<int> la;
	for (int i = 1;i <= N;++i)
	{
		for (int j = 1;j <= M;++j)
		{
			if (A[i][j] == -1)
			{
				s = 0;
				for (int k = 0;k < 4;++k)
				{
					if (isInside(i + dx[k], j + dy[k]) && A[i + dx[k]][j + dy[k]] != -1)
					{
						ok = 0;
						for (pa = 0;pa < la.size();++pa)
							if (la[pa] == D[i + dx[k]][j + dy[k]])
								ok = 1;
						if (!ok)
						{
							s = s + v[D[i + dx[k]][j + dy[k]]] + 1;
							la.push_back(D[i + dx[k]][j + dy[k]]);
						}

					}
				}
				if (s > 0)
					cout << s + 1;
				else
					cout << 0;
				la.clear();
			}
			else
				cout << ".";
		}
		cout << '\n';
	}
	return 0;

}