#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int d[20][20];
int main() {
  int h, w;
  char c;
  bool fld[20][20];
  cin >> h >> w;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      cin >> c;
      if (c == '.') {
        fld[i][j] = true;
      } else {
        fld[i][j] = false;
      }
    }
  int ans = 0;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      for (int y = 0; y < (h); y++)
        for (int x = 0; x < (w); x++) d[y][x] = 1e9;
      d[i][j] = 0;
      queue<pair<int, int> > q;
      q.push(make_pair(i, j));
      while (q.size()) {
        pair<int, int> p = q.front();
        q.pop();
        int ny = p.first, nx = p.second;
        for (int k = 0; k < (4); k++) {
          int nny = ny + dy[k];
          int nnx = nx + dx[k];
          if (nnx >= 0 && nnx < w && nny >= 0 && nny < h) {
            if (fld[nny][nnx]) {
              if (d[nny][nnx] > d[ny][nx] + 1) {
                q.push(make_pair(nny, nnx));
                d[nny][nnx] = d[ny][nx] + 1;
              }
            }
          }
        }
      }
      for (int y = 0; y < (h); y++)
        for (int x = 0; x < (w); x++)
          if (d[y][x] != 1e9) ans = max(ans, d[y][x]);
    }
  cout << ans << endl;
}
