#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const long long LINF = 1e18 + 100;
const int MOD = 1e9 + 7;
int H, W;
int solve(vector<vector<char>> &c, pair<int, int> s, pair<int, int> g) {
  priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
                 greater<pair<int, pair<int, int>>>>
      que;
  que.push({0, s});
  vector<vector<int>> m(H, vector<int>(W, -1));
  while (que.size()) {
    auto val = que.top();
    que.pop();
    int cnt = val.first;
    if (val.second == g) return cnt;
    int i = val.second.first;
    int j = val.second.second;
    if (m[i][j] != -1) continue;
    m[i][j] = cnt;
    if (i - 1 >= 0 && c[i - 1][j] == '.') que.push({cnt + 1, {i - 1, j}});
    if (i + 1 < H && c[i + 1][j] == '.') que.push({cnt + 1, {i + 1, j}});
    if (j - 1 >= 0 && c[i][j - 1] == '.') que.push({cnt + 1, {i, j - 1}});
    if (j + 1 < W && c[i][j + 1] == '.') que.push({cnt + 1, {i, j + 1}});
  }
  return -1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  cin >> H >> W;
  vector<vector<char>> c(H, vector<char>(W));
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) {
      cin >> c[i][j];
    }
  int ans = 0;
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) {
      for (int k = (i); k < (H); k++)
        for (int l = 0; l < (W); l++) {
          if (i >= k && j >= l) continue;
          if (c[i][j] == '#' || c[k][l] == '#') continue;
          int tmp = solve(c, {i, j}, {k, l});
          ans = max(ans, tmp);
        }
    }
  cout << ans << endl;
}
