#include <bits/stdc++.h>
using namespace std;
int ei[4] = {-1, 0, 1, 0};
int ej[4] = {0, -1, 0, 1};
int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < (int)(h); i++) cin >> s[i];
  int ans = 0;
  for (int si = 0; si < (int)(h); si++) {
    for (int sj = 0; sj < (int)(w); sj++) {
      if (s[si][sj] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, 100));
      queue<pair<int, int>> q;
      auto update = [&](int i, int j, int x) {
        if (dist[i][j] != 100) return;
        dist[i][j] = x;
        q.push(pair<int, int>(i, j));
      };
      update(si, sj, 0);
      while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        for (int k = 0; k < (int)(4); k++) {
          int ni = i + ei[k], nj = j + ej[k];
          if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          if (s[ni][nj] == '#') continue;
          update(ni, nj, dist[i][j] + 1);
        }
      }
      for (int i = 0; i < (int)(h); i++) {
        for (int j = 0; j < (int)(w); j++) {
          cout << dist[i][j] << " ";
          if (dist[i][j] == 100) continue;
          if (dist[i][j] > ans) ans = dist[i][j];
        }
        cout << endl;
      }
      cout << endl;
    }
  }
  cout << ans << endl;
  return 0;
}
