#include <bits/stdc++.h>
using namespace std;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, -1, 0, 1};
const int INF = 1e9;
string b[21];
int h, w;
bool inRange(int y, int x) { return y >= 0 && y < h && x >= 0 && x < w; }
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  for (int i = (0); i < (h); ++i) {
    cin >> b[i];
  }
  int ret = 0;
  for (int y = (0); y < (h); ++y)
    for (int x = (0); x < (w); ++x) {
      vector<vector<int> > d(h, vector<int>(w, INF));
      d[y][x] = 0;
      queue<pair<int, int> > q;
      q.push(make_pair(y, x));
      while (!q.empty()) {
        int hy = q.front().first;
        int hx = q.front().second;
        q.pop();
        for (int i = (0); i < (4); ++i) {
          int ny = hy + dy[i];
          int nx = hx + dx[i];
          if (inRange(ny, nx) && b[ny][nx] == '.' && d[ny][nx] == INF) {
            d[ny][nx] = d[hy][hx] + 1;
            q.push(make_pair(ny, nx));
          }
        }
      }
      for (int i = (0); i < (h); ++i)
        for (int j = (0); j < (w); ++j) {
          if (d[i][j] != INF) {
            ret = max(ret, d[i][j]);
          }
        }
    }
  cout << ret << '\n';
  return 0;
}
