#include <bits/stdc++.h>
using namespace std;
const int N = 25;
string g[N];
int n, m;
inline int get_dist(int a, int b) {
  vector<vector<int>> dist(n, vector<int>(m, 1 << N));
  dist[a][b] = 0;
  queue<pair<int, int>> q;
  q.push({a, b});
  while (!q.empty()) {
    auto cur = q.front();
    q.pop();
    for (int i = -1; i <= 1; ++i) {
      for (int j = -1; j <= 1; ++j) {
        if (abs(i - j) != 1) continue;
        int xx = cur.first + i;
        int yy = cur.second + j;
        if (xx >= n || yy >= m || xx < 0 || yy < 0) continue;
        if (g[xx][yy] == '#' || dist[xx][yy] < dist[cur.first][cur.second] + 1)
          continue;
        dist[xx][yy] = dist[cur.first][cur.second] + 1;
        q.push({xx, yy});
      }
    }
  }
  int best = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j] == '.' && i != a && j != b) {
        best = max(dist[i][j], best);
      }
    }
  }
  return best;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> g[i];
  }
  map<pair<int, int>, int> mp;
  int best = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j] == '.') {
        best = max(best, get_dist(i, j));
      }
    }
  }
  cout << best << endl;
}
