#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (auto &e : S) cin >> e;
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j] == '#') continue;
      int sy = i, sx = j;
      for (int k = i + 1; k < H; ++k) {
        for (int l = 0; l < W; ++l) {
          if (S[k][l] == '#') continue;
          int gy = k, gx = l;
          queue<pair<int, int>> q;
          q.emplace(sy, sx);
          vector<vector<int>> v(H, vector<int>(W, -1));
          v[sy][sx] = 0;
          while (!q.empty()) {
            pair<int, int> p = q.front();
            q.pop();
            if (p.first == gy && p.second == gx) break;
            for (int i = 0; i < 4; ++i) {
              int ny = p.first + dy[i], nx = p.second + dx[i];
              if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] == '.' &&
                  v[ny][nx] == -1) {
                q.emplace(ny, nx);
                v[ny][nx] = v[p.first][p.second] + 1;
              }
            }
          }
          ans = max(ans, v[gy][gx]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
