#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  int h, w;
  cin >> h >> w;
  char c[h][w];
  int d[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
      d[h][w] = -1;
    }
  }
  pair<int, int> p;
  int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
  int ny, nx;
  int sx, sy, gx, gy;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (c[i][j] == '.') {
        sx = j;
        sy = i;
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++) {
            if (c[k][l] == '.') {
              gx = l;
              gy = k;
              queue<pair<int, int> > q;
              q.push(pair<int, int>(sy, sx));
              for (int i1 = 0; i1 < h; i1++) {
                for (int j1 = 0; j1 < w; j1++) {
                  d[i1][j1] = -1;
                }
              }
              d[sy][sx] = 0;
              while (q.size() != 0) {
                pair<int, int> mypair = q.front();
                q.pop();
                if ((mypair.first == gy) && (mypair.second == gx)) break;
                for (int i = 0; i < 4; i++) {
                  ny = mypair.first + dy[i];
                  nx = mypair.second + dx[i];
                  if ((0 <= ny) && (ny < h) && (0 <= nx) && (nx < w) &&
                      (c[ny][nx] == '.') && (d[ny][nx] == -1)) {
                    q.push(pair<int, int>(ny, nx));
                    d[ny][nx] = d[mypair.first][mypair.second] + 1;
                  }
                }
              }
              if (d[gy][gx] > ans) ans = d[gy][gx];
              if (sx == 0 && sy == 0) {
                for (int ac = 0; ac < h; ac++) {
                  for (int ab = 0; ab < w; ab++) {
                    cout << d[ac][ab] << " ";
                  }
                  cout << endl;
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans;
  cout << endl;
  return 0;
}
