#include <bits/stdc++.h>
using namespace std;
const int INF = 500;
char maze[20][20];
int d[20][20];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int bfs(int sx, int sy, int h, int w) {
  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[sy][sx] = 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], ny = p.second + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[ny][nx] != '#' &&
          d[ny][nx] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[ny][nx] = d[p.second][p.first] + 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (d[i][j] != INF) ans = max(ans, d[i][j]);
    }
  }
  return ans;
}
void Main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < h; j++) {
      if (maze[i][j] != '#') ans = max(ans, bfs(i, j, h, w));
    }
  }
  cout << ans << endl;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
