#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  int maze[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.')
        maze[i][j] = 1;
      else
        maze[i][j] = 0;
    }
  }
  int max_distance = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == 0) break;
      int d[h][w];
      for (int a = 0; a < h; a++) {
        for (int b = 0; b < w; b++) {
          d[a][b] = 0;
        }
      }
      queue<pair<int, int>> que;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        int x = p.first, y = p.second;
        for (int dx = -1; dx <= 1; dx += 2) {
          if (x + dx < 0 || h <= x + dx) continue;
          int dy = 0;
          if (d[x + dx][y + dy] != 0) continue;
          if (maze[x + dx][y + dy] == 0) continue;
          d[x + dx][y + dy] = d[x][y] + 1;
          max_distance = max(max_distance, d[x][y] + 1);
          que.push(make_pair(x + dx, y + dy));
        }
        for (int dy = -1; dy <= 1; dy += 2) {
          if (y + dy < 0 || w <= y + dy) continue;
          int dx = 0;
          if (d[x + dx][y + dy] != 0) continue;
          if (maze[x + dx][y + dy] == 0) continue;
          d[x + dx][y + dy] = d[x][y] + 1;
          max_distance = max(max_distance, d[x][y] + 1);
          que.push(make_pair(x + dx, y + dy));
        }
      }
    }
  }
  cout << max_distance << endl;
  return 0;
}
