#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int H, W;
vector<string> Graph(21);
int solve(int i, int j, int k, int l) {
  if (Graph[i][j] == '#' || Graph[k][l] == '#') return 0;
  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<P> que;
  que.push(make_pair(i, j));
  dist[i][j] = 0;
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    for (int direction = 0; direction < 4; ++direction) {
      int nh = p.first + dx[direction];
      int nw = p.second + dy[direction];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (dist[nh][nw] > -1) continue;
      if (Graph[nh][nw] == '#') continue;
      dist[nh][nw] = dist[p.first][p.second] + 1;
      if (nh == k && nw == l) {
        return dist[k][l];
      }
      que.push(make_pair(nh, nw));
    }
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (H); ++i) cin >> Graph.at(i);
  int ans = 0;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j)
      for (int k = 0; k < (H); ++k)
        for (int l = 0; l < (W); ++l) {
          ans = max(ans, solve(i, j, k, l));
        }
  cout << ans << endl;
}
