#include <bits/stdc++.h>   using namespace std;   const int maxn = 505 * 505 * 4;   int n;   using vi = vector<int>;   vi G[maxn];   int dfn[maxn];   int low[maxn];   int scc[maxn];   int scnt[maxn];   int ntime;   int scc_cnt;   int sta[maxn];   int sz;   void tarjan(int u) {     dfn[u] = low[u] = ++ntime;     sta[sz++] = u;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (!dfn[v]) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (!scc[v]) {         low[u] = min(low[u], dfn[v]);       }     }     if (low[u] == dfn[u]) {       scc_cnt++;       int tmp;       do {         --sz;         tmp = sta[sz];         scc[tmp] = scc_cnt;         scnt[scc_cnt]++;       } while (tmp != u);     }   }   bool find_bcc() {     sz = 0;     memset(scc, 0, sizeof(scc));     memset(dfn, 0, sizeof(dfn));     memset(scnt, 0, sizeof(scnt));     ntime = scc_cnt = 0;     for (int i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i);     for (int i = 1; i <= n; i += 2) {       if (scc[i] == scc[i + 1]) return false;     }     return true;   }   char s[505][505];   int w, h;   int id(int x, int y) { return (x - 1) * w + y; }   int res[505][505];   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   int main() {     scanf( %d %d , &h, &w);     n = 2 * h * w;     for (int i = 1; i <= h; i += 1) {       scanf( %s , s[i] + 1);     }     for (int i = 1; i <= h; i += 1) {       for (int j = 1; j <= w; j += 1) {         if (s[i][j] ==  . ) continue;         int cnt = 0;         vector<int> lst;         for (int k = 0; k < 4; k += 1) {           int nx = i + dx[k];           int ny = j + dy[k];           if (s[nx][ny] ==  . ) {             cnt += 1;             lst.emplace_back(id(nx, ny));           }         }         if (cnt == 1 || cnt == 3) {           puts( NO );           return 0;         }         if (!cnt) continue;         if (cnt == 2) {           G[lst[0] * 2 - 1].emplace_back(lst[1] * 2);           G[lst[1] * 2 - 1].emplace_back(lst[0] * 2);           G[lst[0] * 2].emplace_back(lst[1] * 2 - 1);           G[lst[1] * 2].emplace_back(lst[0] * 2 - 1);         }         if (cnt == 4) {           for (int i = 0; i < 2; i += 1) {             G[2 * lst[i]].emplace_back(2 * lst[i + 2]);             G[2 * lst[i] - 1].emplace_back(2 * lst[i + 2] - 1);             G[2 * lst[i + 2]].emplace_back(2 * lst[i]);             G[2 * lst[i + 2] - 1].emplace_back(2 * lst[i] - 1);           }           for (int i = 0; i < 4; i += 2) {             int nx = lst[(i + 1) % 4];             G[2 * lst[i] - 1].emplace_back(2 * nx);             G[2 * lst[i]].emplace_back(2 * nx - 1);             nx = lst[(i + 3) % 4];             G[2 * lst[i] - 1].emplace_back(2 * nx);             G[2 * lst[i]].emplace_back(2 * nx - 1);           }         }       }     }     if (!find_bcc())       puts( NO );     else {       puts( YES );       for (int i = 1; i <= h; i += 1) {         for (int j = 1; j <= w; j += 1) {           if (s[i][j] ==  X ) continue;           int cur = id(i, j);           if (scc[2 * cur - 1] < scc[2 * cur])             res[i][j] = 1;           else             res[i][j] = 4;         }       }       for (int i = 1; i <= h; i += 1) {         for (int j = 1; j <= w; j += 1) {           if (s[i][j] ==  . ) continue;           for (int k = 0; k < 4; k += 1) {             int nx = i + dx[k];             int ny = j + dy[k];             if (s[nx][ny] ==  X ) continue;             res[i][j] += res[nx][ny];           }         }       }       for (int i = 1; i <= h; i += 1) {         for (int j = 1; j <= w; j += 1) {           printf( %d%c , res[i][j],    n [j == w]);         }       }     }     return 0;   }