#include <bits/stdc++.h>
using namespace std;
const int N = 25;
string g[N];
int n, m;
bool vis[N][N];
inline int get_dist(int a, int b) {
  vector<vector<int>> dist(n, vector<int>(m, 1 << N));
  dist[a][b] = 0;
  int best = 0;
  queue<pair<int, int>> q;
  q.push({a, b});
  while (!q.empty()) {
    auto cur = q.front();
    q.pop();
    for (int i = -1; i <= 1; ++i) {
      for (int j = -1; j <= 1; ++j) {
        if (abs(i - j) != 1) continue;
        int xx = cur.first + i;
        int yy = cur.second + j;
        if (xx >= n || yy >= m || xx < 0 || yy < 0) continue;
        if (vis[xx][yy] || g[xx][yy] == '#' ||
            dist[xx][yy] < dist[cur.first][cur.second] + 1)
          continue;
        dist[xx][yy] = dist[cur.first][cur.second] + 1;
        best = max(dist[xx][yy], best);
        q.push({xx, yy});
      }
    }
  }
  return best;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> g[i];
  }
  int best = 0;
  vector<vector<int>> mat(n * m, vector<int>(n * m, 1 << N));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j] != '.') continue;
      for (int dx = -1; dx <= 1; ++dx) {
        for (int dy = -1; dy <= 1; ++dy) {
          if (abs(dx - dy) != 1) continue;
          int x = dx + i;
          int y = dy + j;
          if (x < 0 || y < 0 || x >= n || y >= m) continue;
          if (g[x][y] == '#') continue;
          mat[x * n + y][i * n + j] = mat[i * n + j][x * n + y] = 1;
        }
      }
    }
  }
  int size = n * m;
  for (int k = 0; k < size; ++k) {
    for (int i = 0; i < size; ++i) {
      for (int j = 0; j < size; ++j) {
        if (mat[i][k] >= (1 << N) || mat[k][j] >= (1 << N)) continue;
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
      }
    }
  }
  for (int i = 0; i < size; ++i) {
    for (int j = 0; j < size; ++j) {
      if (mat[i][j] < (1 << N)) {
        best = max(best, mat[i][j]);
      }
    }
  }
  cout << best << endl;
}
