#include <bits/stdc++.h>
int n, m;
char mp[23][23];
bool vis[23][23];
int d[4][2] = {0, -1, 0, 1, -1, 0, 1, 0};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mp + i);
  int ans = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      memset(vis, 0, sizeof(vis));
      std::queue<std::pair<int, int> > q;
      vis[i][j] = 1;
      q.push(std::make_pair(i * 100 + j, 0));
      while (!q.empty()) {
        std::pair<int, int> temp = q.front();
        q.pop();
        ans = std::max(temp.second, ans);
        int x = temp.first / 100, y = temp.first % 100;
        for (int dd = 0; dd < 4; dd++) {
          int xx = x + d[dd][0], yy = y + d[dd][1];
          if (xx >= n || xx < 0 || yy >= m || yy < 0) continue;
          if (mp[xx][yy] == '#') continue;
          if (vis[xx][yy]) continue;
          vis[xx][yy] = 1;
          q.push(std::make_pair(xx * 100 + yy, temp.second + 1));
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
