#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1e6;   namespace IO {   const int MAXSIZE = 1 << 20;   char buf[MAXSIZE], *p1, *p2;   inline int gc() {     return (p1 == p2 &&                     (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)                 ? EOF                 : *p1++);   }   inline int rd() {     int x = 0, f = 1;     char c = gc();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = gc();     }     while (isdigit(c)) x = x * 10 + (c ^ 48), c = gc();     return x * f;   }   inline char getc() {     char c = gc();     while (!isgraph(c)) {       c = gc();     }     return c;   }   char pbuf[MAXSIZE], *pp = pbuf;   inline void push(const char &c) {     if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;     *pp++ = c;   }   inline void flush() { fwrite(pbuf, 1, pp - pbuf, stdout), pp = pbuf; }   inline void write(int x) {     static int sta[35];     int top = 0;     do {       sta[top++] = x % 10, x /= 10;     } while (x);     while (top) push(sta[--top] +  0 );   }   }  // namespace IO   int main() {     int n, m;     n = IO::rd();     m = IO::rd();     vector<char> a(n * m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) a[((i)*m + (j))] = IO::getc();     vector<int> dp(n * m, INF);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (a[((i)*m + (j))] !=  X )           dp[((i)*m + (j))] = 0;         else {           if (i && j)             dp[((i)*m + (j))] =                 min(dp[((i - 1) * m + (j - 1))],                     min(dp[((i - 1) * m + (j))], dp[((i)*m + (j - 1))])) +                 1;           else             dp[((i)*m + (j))] = 1;         }       }     int l = 0, r = min(n, m);     auto dp2 = dp;     while (l < r) {       int mid = (l + r + 1) / 2;       int ok = 1;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           if (dp[((i)*m + (j))] < mid) dp[((i)*m + (j))] = 0;         }       for (int i = n - 1; i >= 0; i--)         for (int j = m - 1; j >= 0; j--) {           if (i != n - 1)             dp[((i)*m + (j))] =                 max(dp[((i)*m + (j))], dp[((i + 1) * m + (j))] - 1);           if (j != m - 1)             dp[((i)*m + (j))] = max(dp[((i)*m + (j))], dp[((i)*m + (j + 1))] - 1);           if (i != n - 1 && j != m - 1)             dp[((i)*m + (j))] =                 max(dp[((i)*m + (j))], dp[((i + 1) * m + (j + 1))] - 1);           if (dp[((i)*m + (j))] == 0 && a[((i)*m + (j))] ==  X ) {             ok = 0;             goto zml;           }         }     zml:       if (ok) {         l = mid;       } else {         r = mid - 1;       }       dp = dp2;     }     int ans = l;     IO::write((ans - 1) / 2);     int a1 = (ans - 1) / 2;     int a2 = ans / 2;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         a[((i)*m + (j))] =  . ;         if (dp[((i)*m + (j))] >= ans) {           a[((i - a1) * m + (j - a1))] =  X ;           a[((i - a1) * m + (j - a2))] =  X ;           a[((i - a2) * m + (j - a1))] =  X ;           a[((i - a2) * m + (j - a2))] =  X ;         }       }     IO::push(  n );     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) IO::push(a[((i)*m + (j))]);       IO::push(  n );     }     IO::flush();   }