#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};
int bfs(vector<string> &s, int sy, int sx, int gy, int gx) {
  int h = s.size(), w = s[0].size();
  vector<vector<int>> dist(h, vector<int>(w, 1e9));
  queue<pair<pair<int, int>, int>> que;
  que.push({{sy, sx}, 0});
  while (!que.empty()) {
    auto tmp = que.front();
    que.pop();
    int y = tmp.first.first, x = tmp.first.second, d = tmp.second;
    dist[y][x] = d;
    if (gy == y && gx == x) break;
    for (int i = 0; i < 4; i++) {
      int yy = y + dy[i], xx = x + dx[i];
      if (yy < 0 || yy >= h || xx < 0 || xx >= w || s[yy][xx] == '#') continue;
      que.push({{y + dy[i], x + dx[i]}, d + 1});
    }
  }
  return dist[gy][gx];
}
int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (s[k][l] == '#') continue;
          ans = max(ans, bfs(s, i, j, k, l));
        }
      }
    }
  }
  printf("%d\n", ans);
}
