#include <bits/stdc++.h>
using namespace std;
char G[44][44];
int visit[44][44] = {0};
int h, w;
int inbound(int i, int j) {
  return i > 0 && j > 0 && i <= h && j <= w && G[i][j] == '.';
}
struct node {
  int a, b, c;
};
int a[4][2] = {0, 1, -1, 0, 0, -1, 1, 0};
int solve(int z, int c) {
  int ret = 0;
  memset(visit, 0, sizeof visit);
  queue<node> qq;
  qq.push({z, c, 0});
  visit[z][c] = 1;
  while (!qq.empty()) {
    int x = qq.front().a;
    int y = qq.front().b;
    int len = qq.front().c;
    qq.pop();
    ret = max(ret, len);
    for (int i = 0; i < 4; i++) {
      int x1 = x + a[i][0];
      int y1 = y + a[i][1];
      if (inbound(x1, y1) && !visit[x1][y1]) {
        visit[x1][y1] = 1;
        qq.push({x1, y1, len + 1});
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    cin >> G[i] + 1;
  }
  int res = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) res = max(res, solve(i, j));
  }
  cout << res << endl;
  return 0;
}
