#include <bits/stdc++.h>
using namespace std;
int h, w;
char a[20][20];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int d[21][21];
queue<pair<int, int> > q;
bool v[21][21];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> h >> w;
  char c;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
    }
  }
  int sol = 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] = 1000000;
          v[y][x] = false;
        }
      }
      if (a[i][j] == '.') {
        int mxDist = 0;
        d[i][j] = 0;
        q.push(make_pair(i, j));
        v[i][j] = true;
        while (!q.empty()) {
          pair<int, int> z = q.front();
          q.pop();
          int y = z.first, x = z.second;
          int dist = d[y][x];
          for (int p = 0; p < 4; ++p) {
            int t1, t2;
            t1 = y + dy[p];
            t2 = x + dx[p];
            if (t1 >= 0 && t1 < h && t2 >= 0 && t1 < w) {
              if (a[t1][t2] == '.' && !v[t1][t2]) {
                d[t1][t2] = 1 + dist;
                mxDist = max(mxDist, 1 + dist);
                q.push(make_pair(t1, t2));
                v[t1][t2] = true;
              }
            }
          }
        }
        sol = max(sol, mxDist);
      }
    }
  }
  cout << sol;
  return 0;
}
