#include <bits/stdc++.h>
using namespace std;
struct dim2 {
  int x;
  int y;
  int cnt;
};
int solve(int h, int w, int x, int y, vector<string> &map) {
  if (map[x][y] == '#') {
    return 0;
  }
  queue<dim2> queue;
  dim2 start;
  start.x = x;
  start.y = y, start.cnt = 0;
  queue.push(start);
  int tmpx[4] = {0, 1, 0, -1};
  int tmpy[4] = {1, 0, -1, 0};
  vector<vector<bool>> flag = vector<vector<bool>>(h, vector<bool>(w, false));
  int ans = 0;
  while (!queue.empty()) {
    dim2 now = queue.front();
    now.cnt += 1;
    ans = max(ans, now.cnt);
    flag[now.x][now.y] = true;
    queue.pop();
    for (int i = 0; i < 4; i++) {
      dim2 tmp = now;
      tmp.x += tmpx[i];
      tmp.y += tmpy[i];
      if (tmp.x >= h || tmp.x < 0 || tmp.y >= w || tmp.y < 0 ||
          flag[tmp.x][tmp.y]) {
        continue;
      }
      if (map[tmp.x][tmp.y] == '#') {
        continue;
      }
      queue.push(tmp);
    }
  }
  return ans;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> map(h);
  for (int i = 0; i < h; i++) {
    cin >> map[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, solve(h, w, i, j, map));
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
