#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int h, w;
vector<string> s;
bool can(pair<int, int> a, vector<vector<int>> dist) {
  int x = a.first;
  int y = a.second;
  return x >= 0 && x < h && y >= 0 && y < w && s[x][y] == '.' &&
         dist[x][y] == -1;
}
int vectormax(vector<vector<int>> dist) {
  int ans = 0;
  for (int i = 0; i < dist.size(); i++) {
    for (int j = 0; j < dist[i].size(); j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  return ans;
}
int main() {
  cin >> h >> w;
  s.resize(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
  queue<pair<int, int>> que;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      vector<vector<int>> dist(h, vector<int>(w, -1));
      if (s[i][j] == '.') {
        que.push(make_pair(i, j));
        dist[i][j] = 0;
        while (!que.empty()) {
          pair<int, int> temp = que.front();
          que.pop();
          for (int k = 0; k < 4; k++) {
            pair<int, int> tmp;
            tmp.first = temp.first + dx[k];
            tmp.second = temp.second + dy[k];
            if (can(tmp, dist)) {
              dist[tmp.first][tmp.second] = dist[temp.first][temp.second] + 1;
              que.push(tmp);
            }
          }
        }
      }
      ans = vectormax(dist);
    }
  }
  cout << ans << endl;
}
