#include <bits/stdc++.h>
int64_t inf = 1000000007;
int64_t giant = 4000000000000000037;
using namespace std;
int h, w;
vector<string> mp;
int ans = 0;
void input() {
  cin >> h >> w;
  mp.resize(h);
  for (int i = 0; i < h; i++) {
    cin >> mp[i];
  }
}
int main() {
  input();
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (mp[y][x] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, -1));
      queue<pair<int, int>> to_visit;
      dist[y][x] = 0;
      to_visit.push({y, x});
      while (!to_visit.empty()) {
        pair<int, int> v = to_visit.front();
        to_visit.pop();
        if (v.second > 0) {
          if (mp[v.first][v.second - 1] == '.' &&
              dist[v.first][v.second - 1] < 0) {
            to_visit.push({v.first, v.second - 1});
            dist[v.first][v.second - 1] = dist[v.first][v.second] + 1;
          }
        }
        if (v.second < w - 1) {
          if (mp[v.first][v.second + 1] == '.' &&
              dist[v.first][v.second + 1] < 0) {
            to_visit.push({v.first, v.second + 1});
            dist[v.first][v.second + 1] = dist[v.first][v.second] + 1;
          }
        }
        if (v.first > 0) {
          if (mp[v.first - 1][v.second] == '.' &&
              dist[v.first - 1][v.second] < 0) {
            to_visit.push({v.first - 1, v.second});
            dist[v.first - 1][v.second] = dist[v.first][v.second] + 1;
          }
        }
        if (v.first < h - 1) {
          if (mp[v.first + 1][v.second] == '.' &&
              dist[v.first + 1][v.second] < 0) {
            to_visit.push({v.first + 1, v.second});
            dist[v.first + 1][v.second] = dist[v.first][v.second] + 1;
          }
        }
      }
      int pre = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          pre = max(pre, dist[i][j]);
          cout << dist[i][j] << " ";
        }
        cout << endl;
      }
      ans = max(ans, pre);
    }
  }
  cout << ans << endl;
  return 0;
}
