#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
int di[] = {-1, 0, 1, 0};
int dj[] = {0, -1, 0, 1};
int h, w;
vector<vector<char>> mp;
void bfs(vector<vector<int>>& c, int a, int b) {
  queue<pair<int, int>> que;
  que.push(make_pair(a, b));
  while (!que.empty()) {
    int i = que.front().first;
    int j = que.front().second;
    que.pop();
    for (int k = 0; k < (4); ++k) {
      int dx = i + di[k], dy = j + dj[k];
      if (dx < 0 || dx >= h || dy < 0 || dy >= w) continue;
      if (c[dx][dy] != inf) continue;
      if (mp[dx][dy] == '#') continue;
      que.push(make_pair(dx, dy));
      c[dx][dy] = c[i][j] + 1;
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  mp.resize(h, vector<char>(w));
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) cin >> mp[i][j];
  int just_ans = 0;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      vector<vector<int>> ans(h, vector<int>(w, inf));
      ans[i][j] = 0;
      bfs(ans, i, j);
      for (int ri = 0; ri < (h); ++ri)
        for (int rj = 0; rj < (w); ++rj) {
          if (ans[ri][rj] == inf || mp[ri][rj] == '#') continue;
          just_ans = max(just_ans, ans[ri][rj]);
        }
    }
  cout << (just_ans) << endl;
  return 0;
}
