#include <bits/stdc++.h>
using namespace std;
char mp[25][25];
struct kkk {
  int x, y;
};
int dis[25][25][25][25];
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> mp[i][j];
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (mp[i][j] != '.') {
        continue;
      }
      queue<kkk> q;
      kkk tmp;
      tmp.x = i, tmp.y = j;
      q.push(tmp);
      kkk now, nxt;
      dis[i][j][i][j] = 0;
      while (!q.empty()) {
        now = q.front();
        q.pop();
        if (now.y != w && mp[now.x][now.y + 1] == '.' &&
            !dis[i][j][now.x][now.y + 1]) {
          nxt.x = now.x, nxt.y = now.y + 1;
          dis[i][j][nxt.x][nxt.y] = dis[i][j][now.x][now.y] + 1;
          q.push(nxt);
        }
        if (now.x != h && mp[now.x + 1][now.y] == '.' &&
            !dis[i][j][now.x + 1][now.y]) {
          nxt.x = now.x + 1, nxt.y = now.y;
          dis[i][j][nxt.x][nxt.y] = dis[i][j][now.x][now.y] + 1;
          q.push(nxt);
        }
        if (now.x != 1 && mp[now.x - 1][now.y] == '.' &&
            !dis[i][j][now.x - 1][now.y]) {
          nxt.x = now.x - 1, nxt.y = now.y;
          dis[i][j][nxt.x][nxt.y] = dis[i][j][now.x][now.y] + 1;
          q.push(nxt);
        }
        if (now.y != 1 && mp[now.x][now.y - 1] == '.' &&
            !dis[i][j][now.x][now.y - 1]) {
          nxt.x = now.x, nxt.y = now.y - 1;
          dis[i][j][nxt.x][nxt.y] = dis[i][j][now.x][now.y] + 1;
          q.push(nxt);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      for (int k = 1; k <= h; k++) {
        for (int l = 1; l <= w; l++) {
          ans = max(ans, dis[i][j][k][l]);
        }
      }
    }
  }
  cout << ans;
  return 0;
}
