#include <bits/stdc++.h>
using namespace std;
int h, w;
char grid[22][22];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
bool valid(int x, int y) {
  return (0 <= x && x < h && 0 <= y && y < w && grid[x][y] == '.');
}
int bfs(int x, int y) {
  map<pair<int, int>, int> dist;
  queue<pair<int, int>> q;
  q.push(make_pair(x, y));
  dist[make_pair(x, y)] = 0;
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    int x = u.first;
    int y = u.second;
    for (int k = 0; k < 4; k++) {
      int i = x + dx[k];
      int j = y + dy[k];
      if (valid(i, j) && dist.find(make_pair(i, j)) == dist.end()) {
        dist[make_pair(i, j)] = 1 + dist[make_pair(x, y)];
        q.push(make_pair(i, j));
      }
    }
  }
  int farthest = 0;
  for (auto it : dist) {
    farthest = max(farthest, it.second);
  }
  return farthest;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << "\n";
  return 0;
}
