#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cin >> s[i][j];
  }
  int m = 0;
  for (int sx = 0; sx < h; sx++) {
    for (int sy = 0; sy < w; sy++) {
      for (int gx = 0; gx < h; gx++) {
        for (int gy = 0; gy < w; gy++) {
          bool b = true;
          vector<vector<int>> dist(h, vector<int>(w, 1000));
          if (sx == gx && sy == gy) b = false;
          if (s[sx][sy] == '#' || s[gx][gy] == '#') b = false;
          dist[sx][sy] = 0;
          queue<int> x;
          queue<int> y;
          x.push(sx);
          y.push(sy);
          while (x.front() != gx || y.front() != gy) {
            int xf = x.front();
            int yf = y.front();
            if (xf < h - 1 && s[xf + 1][yf] == '.') {
              x.push(xf + 1);
              y.push(yf);
              dist[xf + 1][yf] = min(dist[xf + 1][yf], dist[xf][yf] + 1);
            }
            if (yf < w - 1 && s[xf][yf + 1] == '.') {
              x.push(xf);
              y.push(yf + 1);
              dist[xf][yf + 1] = min(dist[xf][yf + 1], dist[xf][yf] + 1);
            }
            if (xf > 0 && s[xf - 1][yf] == '.') {
              x.push(xf - 1);
              y.push(yf);
              dist[xf - 1][yf] = min(dist[xf - 1][yf], dist[xf][yf] + 1);
            }
            if (yf > 0 && s[xf][yf - 1] == '.') {
              x.push(xf);
              y.push(yf - 1);
              dist[xf][yf - 1] = min(dist[xf][yf - 1], dist[xf][yf] + 1);
            }
          }
          if (b) m = max(m, dist[x.front()][y.front()]);
        }
      }
    }
  }
  cout << m << endl;
  return 0;
}
