#include <bits/stdc++.h>
using namespace std;
int h, w;
int math0[20][20], math1[20][20][20][20];
int res = -1;
int dy[4] = {0, 0, 1, -1}, dx[4] = {1, -1, 0, 0};
int bfs(int sy, int sx) {
  if (math1[sy][sx] == 0) return 0;
  math1[sy][sx][sy][sx] = 0;
  queue<pair<int, int>> que;
  que.push(pair<int, int>(sy, sx));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (0 <= ny && ny < h && 0 <= nx && nx < w) {
        if (math1[sy][sx][ny][nx] == -1) {
          math1[sy][sx][ny][nx] = math1[sy][sx][p.first][p.second] + 1;
          res = max(math1[sy][sx][ny][nx], res);
          que.push(pair<int, int>(ny, nx));
        }
      }
    }
  }
  return res;
};
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char tmp;
      cin >> tmp;
      if (tmp == '#')
        math0[i][j] = 0;
      else
        math0[i][j] = -1;
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          math1[i][j][k][l] = math0[k][l];
        }
      }
      ans = max(bfs(i, j), ans);
    }
  }
  cout << ans << endl;
}
