#include <bits/stdc++.h>
using namespace std;
const int inf = 100000000;
int h, w;
int sx, sy;
int d[22][22];
char m[22][22];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int cnt = 0;
int bfs() {
  for (int a = 0; a < h; a++) {
    for (int b = 0; b < w; b++) {
      sx = a;
      sy = b;
      queue<pair<int, int> > que;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          d[i][j] = inf;
        }
      }
      que.push(pair<int, int>(sx, sy));
      d[sx][sy] = 0;
      while (que.size()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          int nx = p.first + dx[i];
          int ny = p.second + dy[i];
          if (0 <= nx && 0 <= ny && nx < h && ny < w && m[nx][ny] != '#' &&
              d[nx][ny] == inf) {
            que.push(pair<int, int>(nx, ny));
            d[nx][ny] = d[p.first][p.second] + 1;
            cnt = max(cnt, d[nx][ny]);
          }
        }
      }
    }
  }
  return cnt;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> m[i][j];
    }
  }
  int ans;
  ans = bfs();
  cout << ans;
}
