#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int inf = 1000;
int h, w;
void dfs(vector<vector<char>> &s, int i, int j, vector<vector<int>> &d) {
  s[i][j] = 'x';
  if (i + 1 < h) {
    if (s[i + 1][j] != '#') {
      d[i + 1][j] = min(d[i + 1][j], d[i][j] + 1);
    }
  }
  if (j + 1 < w) {
    if (s[i][j + 1] != '#') {
      d[i][j + 1] = min(d[i][j + 1], d[i][j] + 1);
    }
  }
  if (i - 1 >= 0) {
    if (s[i - 1][j] != '#') {
      d[i - 1][j] = min(d[i - 1][j], d[i][j] + 1);
    }
  }
  if (j - 1 >= 0) {
    if (s[i][j - 1] != '#') {
      d[i][j - 1] = min(d[i][j - 1], d[i][j] + 1);
    }
  }
  if ((i + 1 < h) && (s[i + 1][j] == '.')) dfs(s, i + 1, j, d);
  if ((j + 1 < w) && (s[i][j + 1] == '.')) dfs(s, i, j + 1, d);
  if ((i - 1 >= 0) && (s[i - 1][j] == '.')) dfs(s, i - 1, j, d);
  if ((j - 1 >= 0) && (s[i][j - 1] == '.')) dfs(s, i, j - 1, d);
  return;
}
int main() {
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w, '-'));
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) cin >> s[i][j];
  int ans = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      if (s[i][j] == '#') continue;
      vector<vector<char>> t(h, vector<char>(w, '-'));
      for (int a = 0; a < (int)(h); a++)
        for (int b = 0; b < (int)(w); b++) t[a][b] = s[a][b];
      vector<vector<int>> d(h, vector<int>(w, inf));
      d[i][j] = 0;
      dfs(t, i, j, d);
      int m = 0;
      for (int a = 0; a < (int)(h); a++)
        for (int b = 0; b < (int)(w); b++) {
          if (d[a][b] != inf) m = max(m, d[a][b]);
        }
      ans = max(ans, m);
    }
  cout << ans << endl;
}
