#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
const int NMAX = 100005;
using namespace std;
char mp[20 + 2][20 + 2];
int dirx[] = {1, 0, -1, 0};
int diry[] = {0, 1, 0, -1};
vector<vector<int> > done(22, vector<int>(22, 0));
int bfs(int ix, int iy, int gx, int gy) {
  int ans = 100000;
  queue<pair<int, int> > q;
  queue<int> qw;
  q.push(make_pair(ix, iy));
  qw.push(0);
  while (q.size() > 0) {
    auto tmp = q.front();
    q.pop();
    int x = tmp.first;
    int y = tmp.second;
    int w = qw.front();
    qw.pop();
    if (done[x][y] == 1) continue;
    done[x][y] = 1;
    if (x == gx && y == gy) {
      ans = w;
      break;
    }
    for (int i = 0; i < 4; i++) {
      if (mp[x + dirx[i]][y + diry[i]] == '.') {
        if (done[x + dirx[i]][y + diry[i]] == 0) {
          q.push(make_pair(x + dirx[i], y + diry[i]));
          qw.push(w + 1);
        }
      }
    }
  }
  return ans;
}
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      if (i == 0 || j == 0 || i == h + 1 || j == w + 1) {
        mp[i][j] = '#';
      } else {
        cin >> mp[i][j];
      }
    }
  }
  int ans = 0;
  for (int sx = 1; sx < h + 1; sx++) {
    for (int sy = 1; sy < w + 1; sy++) {
      for (int gx = 1; gx < h + 1; gx++) {
        for (int gy = 1; gy < w + 1; gy++) {
          if (sx >= gx && sy >= gy) continue;
          for (int i = 0; i < 22; i++) {
            for (int j = 0; j < 22; j++) {
              done[i][j] = 0;
            }
          }
          int tmp = bfs(sx, sy, gx, gy);
          if (tmp == 100000) continue;
          ans = max(ans, tmp);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
