#include <bits/stdc++.h>
using namespace std;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 100000000;
const int BINF = 100000000000000001;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<vector<bool>> S(H + 2, vector<bool>(W + 2, false));
  for (int i = 1; i < H + 1; ++i) {
    string input;
    cin >> input;
    for (int j = 1; j < W + 1; ++j) {
      if (input[j - 1] == '.') S[i][j] = true;
    }
  }
  int ans = 0;
  for (int i = 1; i < H + 1; ++i) {
    for (int j = 1; j < W + 1; ++j) {
      if (S[i][j] != false) {
        std::queue<std::pair<int, std::pair<int, int>>> wait;
        wait.push(std::make_pair(0, std::make_pair(i, j)));
        S[i][j] = false;
        while (!wait.empty()) {
          int nowcost = wait.front().first;
          int nowY = wait.front().second.first;
          int nowX = wait.front().second.second;
          wait.pop();
          ans = max(nowcost, ans);
          for (int k = 0; k < 4; k++) {
            int nextY = nowY + dy[k];
            int nextX = nowX + dx[k];
            if (S[nextY][nextX]) {
              wait.push(
                  std::make_pair(nowcost + 1, std::make_pair(nextY, nextX)));
              S[nextY][nextX] = false;
            }
          }
        }
        S[i][j] = true;
      }
    }
  }
  for (int i = 0; i <= H; ++i) {
    for (int j = 0; j <= W; ++j) {
      if (S[i][j] == true)
        cout << ".";
      else
        cout << "#";
    }
    cout << endl;
  }
  cout << ans << endl;
  return 0;
}
