#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
int graph[400][400];
int size = 0;
int main() {
  int H, W;
  cin >> H >> W;
  char table[H + 2][W + 2];
  for (int i = 0; i < H + 2; ++i) {
    table[i][0] = '#';
    table[i][W + 1] = '#';
  }
  for (int i = 0; i < W + 2; ++i) {
    table[0][i] = '#';
    table[H + 1][i] = '#';
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> table[i + 1][j + 1];
    }
  }
  size = H * W;
  for (int i = 0; i < size; ++i) {
    for (int j = 0; j < size; ++j) {
      graph[i][j] = INF;
    }
    graph[i][i] = 0;
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (table[i + 1][j + 1] == '.') {
        if (table[i + 1][j] == '.') {
          graph[(i)*W + j][(i)*W + (j - 1)] = 1;
          graph[(i)*W + (j - 1)][(i)*W + j] = 1;
        }
        if (table[i + 1][j + 2] == '.') {
          graph[(i)*W + j][(i)*W + (j + 1)] = 1;
          graph[(i)*W + (j + 1)][(i)*W + j] = 1;
        }
        if (table[i][j + 1] == '.') {
          graph[(i)*W + j][(i - 1) * W + j] = 1;
          graph[(i - 1) * W + j][(i)*W + j] = 1;
        }
        if (table[i + 2][j + 1] == '.') {
          graph[(i)*W + j][(i + 1) * W + j] = 1;
          graph[(i + 1) * W + j][(i)*W + j] = 1;
        }
      }
    }
  }
  for (int i = 0; i < size; ++i) {
    for (int j = 0; j < size; ++j) {
      if (graph[i][j] == INF) {
        cout << "#"
             << " ";
      } else {
        cout << graph[i][j] << " ";
      }
    }
    cout << endl;
  }
  for (int i = 0; i < size; i++)
    for (int j = 0; j < size; j++)
      for (int k = 0; k < size; k++)
        graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);
  int ans = 0;
  for (int i = 0; i < size; i++) {
    if (table[i / W + 1][i % W + 1] == '#') {
      continue;
    }
    for (int j = 0; j < size; j++) {
      if (table[j / W + 1][j % W + 1] == '#') {
        continue;
      }
      cout << i << " " << j << " " << graph[i][j] << endl;
      ans = max(graph[i][j], ans);
    }
  }
  cout << "ans" << endl;
  cout << ans << endl;
  return 0;
}
