#include <bits/stdc++.h>
using namespace std;
int f(vector<vector<bool>> &maze, pair<int, int> s, pair<int, int> g) {
  vector<vector<bool>> notVisited = maze;
  queue<pair<pair<int, int>, int>> q;
  q.push({s, 0});
  while (!q.empty()) {
    auto p = q.front();
    int x = p.first.first, y = p.first.second, d = p.second;
    q.pop();
    if (x == g.first && y == g.second) return d;
    notVisited[y][x] = false;
    pair<int, int> ds[4] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
    for (int i = 0; i < 4; ++i) {
      int nx = x + ds[i].first, ny = y + ds[i].second;
      if (!maze[ny][nx]) continue;
      if (!notVisited[ny][nx]) continue;
      q.push({{nx, ny}, d + 1});
    }
  }
  return -1;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> maze(h + 2, vector<bool>(w + 2));
  for (int y = 0; y < h; ++y) {
    string s;
    cin >> s;
    for (int x = 0; x < w; ++x) {
      maze[y + 1][x + 1] = s[x] == '.';
    }
  }
  int ans = 0;
  for (int sy = 1; sy <= h; ++sy) {
    for (int sx = 1; sx <= w; ++sx) {
      if (!maze[sy][sx]) continue;
      for (int gy = 1; gy <= h; ++gy) {
        for (int gx = 1; gx <= w; ++gx) {
          if (!maze[gy][gx]) continue;
          ans = max(ans, f(maze, {sx, sy}, {gx, gy}));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
