#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<vector<int> > fi(20, vector<int>(20, 0));
int bfs(int a, int b, int c, int d) {
  vector<vector<int> > dist(h, vector<int>(w, 0));
  vector<vector<int> > used(h, vector<int>(w, 0));
  queue<pair<int, int> > q;
  pair<int, int> now;
  q.push({a, b});
  int x, y;
  used[a][b] = 1;
  int ret = 0;
  while (!q.empty()) {
    now = q.front();
    q.pop();
    y = now.first;
    x = now.second;
    for (int k = -1; k < 2; k++) {
      for (int l = -1; l < 2; l++) {
        if ((k && !l) || (!k && l)) {
          if (y + k >= 0 && y + k < h && x + l >= 0 && x + l < w) {
            if (!fi[y + k][x + l] && !used[y + k][x + l]) {
              q.push({y + k, x + l});
              dist[y + k][x + l] = dist[y][x] + 1;
              ret = max(ret, dist[y + k][x + l]);
              used[y + k][x + l] = 1;
            }
          }
        }
      }
    }
  }
  return ret;
}
int main() {
  cin >> h >> w;
  char r;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> r;
      if (r == '.') {
        fi[i][j] = 0;
      } else {
        fi[i][j] = 1;
      }
    }
  }
  int maxi = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (i == k && j == l) continue;
          maxi = max(maxi, bfs(i, j, k, l));
        }
      }
    }
  }
  cout << maxi << endl;
}
