#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll N = 1e6 + 100;   ll n;   ll m;   ll **arr() {     ll **res = new ll *[n + 2];     for (ll i = 0; i < n + 2; ++i) {       res[i] = new ll[m + 2];       fill_n(res[i], m + 2, 0);     }     return res;   }   ll **inp;   ll **ans;   void pref(ll **a) {     for (ll i = 1; i <= n + 1; ++i) {       for (ll j = 1; j <= m + 1; ++j) {         a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];       }     }   }   ll sum(ll **a, ll il, ll ir, ll jl, ll jr) {     il = max(il, 1ll);     ir = min(ir, n);     jl = max(jl, 1ll);     jr = min(jr, m);     --il;     --jl;     return a[ir][jr] - a[ir][jl] - a[il][jr] + a[il][jl];   }   ll sq(ll first) { return first * first; }   bool check(ll t) {     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         ans[i][j] = sum(inp, i - t, i + t, j - t, j + t) == sq(2 * t + 1);       }     }     pref(ans);     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         if (sum(inp, i, i, j, j) && sum(ans, i - t, i + t, j - t, j + t) == 0) {           return false;         }       }     }     return true;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     inp = arr();     ans = arr();     for (ll i = 1; i <= n; ++i) {       string s;       cin >> s;       for (ll j = 1; j <= m; ++j) {         inp[i][j] = s[j - 1] ==  X ;       }     }     pref(inp);     ll lef = 0, rig = N;     while (rig - lef > 1) {       ll mid = (lef + rig) / 2;       if (check(mid)) {         lef = mid;       } else {         rig = mid;       }     }     assert(check(lef));     cout << lef <<   n ;     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         cout <<  .X [sum(ans, i, i, j, j)];       }       cout <<   n ;     }     return 0;   }   