#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const long long INF = 5e18;
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  int h, w, cnt, ans = 0, dist[25][25] = {}, dx[4] = {1, 0, -1, 0},
                 dy[4] = {0, 1, 0, -1};
  cin >> h >> w;
  string s[25] = {};
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        for (int i = 0; i < h; i++) {
          for (int j = 0; j < w; j++) {
            dist[i][j] = inf;
          }
        }
        queue<pair<int, int> > q;
        q.push(pair<int, int>(j, i));
        dist[j][i] = 0;
        cnt = 0;
        while (q.size()) {
          pair<int, int> p = q.front();
          q.pop();
          for (int i = 0; i < 4; i++) {
            int nx = p.second + dx[i], ny = p.first + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] == '.' &&
                dist[ny][nx] == inf) {
              q.push(pair<int, int>(ny, nx));
              dist[ny][nx] = dist[p.first][p.second] + 1;
              cnt = max(cnt, dist[ny][nx]);
            }
          }
        }
        ans = max(ans, cnt);
      }
    }
  }
  cout << ans << endl;
}
