#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  char a[20][20];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
  int ans = 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 (a[i][j] == '#' || a[k][l] == '#') {
            continue;
          }
          int sx = i, sy = j;
          int gx = k, gy = l;
          queue<pair<pair<int, int>, int> > que;
          que.push(make_pair(make_pair(sx, sy), 0));
          int s[20][20] = {};
          s[sx][sy] = 1;
          bool f = true;
          int diff;
          while (!que.empty() && f) {
            pair<pair<int, int>, int> hoge = que.front();
            que.pop();
            int nx = hoge.first.first, ny = hoge.first.second;
            for (int m = 0; m < 4; m++) {
              int tx = nx + dx[m], ty = ny + dy[m];
              if (0 <= tx && tx < h && 0 <= ty && ty < w && a[tx][ty] == '.') {
                if (tx == gx && ty == gy) {
                  f = false;
                  diff = hoge.second + 1;
                } else if (s[tx][ty] == 0) {
                  s[tx][ty] = 1;
                  que.push(make_pair(make_pair(tx, ty), hoge.second + 1));
                }
              }
            }
          }
          ans = max(ans, diff);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
