#include <bits/stdc++.h>
using namespace std;
string s[20];
int dis[20][20];
int ans = 0, h, w;
struct Corr {
  int y;
  int x;
  int depth;
};
queue<Corr> q;
void reset() {
  for (int(i) = 0; i < (20); i++)
    for (int(j) = 0; j < (20); j++) dis[i][j] = -1;
}
int bfs(int y, int x) {
  Corr start = {y, x, 0};
  q.push(start);
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    int xx = now.x, yy = now.y, depth = now.depth;
    int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    for (int(i) = 0; i < (4); i++) {
      Corr next = {yy + dy[i], xx + dx[i], depth + 1};
      if (next.x >= 0 && next.x < w && next.y >= 0 && next.y < h &&
          s[next.y].at(next.x) == '.' && dis[next.y][next.x] == -1) {
        dis[next.y][next.x] = 1;
        ans = max(ans, depth + 1);
        q.push(next);
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int(i) = 0; i < (h); i++) cin >> s[i];
  for (int(i) = 0; i < (h); i++)
    for (int(j) = 0; j < (w); j++) {
      reset();
      bfs(i, j);
    }
  cout << ans;
}
