#include <bits/stdc++.h>
using namespace std;
void preprocess(void) { return; }
char st[22][22];
int dis[22][22];
vector<pair<int, int> > moves = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
int h, w;
int solve(int X, int Y) {
  memset(dis, -1, sizeof dis);
  queue<pair<int, int> > q;
  q.push({X, Y});
  dis[X][Y] = 0;
  while (!q.empty()) {
    auto f = q.front();
    int x = f.first, y = f.second;
    q.pop();
    for (auto m : moves) {
      int xx = x + m.first, yy = y + m.second;
      if (xx < 0 || yy < 0 || xx >= h || yy >= w) {
        continue;
      }
      if (dis[xx][yy] != -1 || st[xx][yy] == '#') {
        continue;
      } else {
        dis[xx][yy] = dis[x][y] + 1;
        q.push({xx, yy});
      }
    }
  }
  int f = 0;
  for (auto i = (0); i < h; i++) {
    for (auto j = (0); j < w; j++) {
      f = max(f, dis[i][j]);
    }
  }
  return f;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  cin >> h >> w;
  for (auto i = (0); i < h; i++) {
    for (auto j = (0); j < w; j++) cin >> st[i][j];
  }
  int ans = 0;
  for (auto i = (0); i < h; i++) {
    for (auto j = (0); j < w; j++) {
      ans = max(ans, solve(i, j));
    }
  }
  cout << ans << endl;
}
