#include <bits/stdc++.h>
using namespace std;
template <class T>
T maxAny(T a, T b) {
  if (a > b)
    return a;
  else
    return b;
}
template <class T>
T minAny(T a, T b) {
  if (a > b)
    return b;
  else
    return a;
}
int h, w, ans = 0;
vector<vector<int>> dist(20, vector<int>(20, 0));
char s[20][20];
void dfs(int x, int y, int prex, int prey, int startx, int starty) {
  if (x < 0 || y < 0 || x >= h || y >= w || s[x][y] == '#' ||
      (x == startx && y == starty)) {
    return;
  } else {
    if (dist[x][y] == 0)
      dist[x][y] = dist[prex][prey] + 1;
    else
      dist[x][y] = min(dist[x][y], dist[prex][prey] + 1);
    if (dist[prex][prey] + 1 == dist[x][y]) {
      dfs(x + 1, y, x, y, startx, starty);
      dfs(x, y + 1, x, y, startx, starty);
      dfs(x - 1, y, x, y, startx, starty);
      dfs(x, y - 1, x, y, startx, starty);
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) cin >> s[i][j];
  for (int i = 0; i < (h); i++) {
    for (int j = 0; j < (w); j++) {
      if (s[i][j] == '.') {
        dfs(i + 1, j, i, j, i, j);
        dfs(i, j + 1, i, j, i, j);
        dfs(i - 1, j, i, j, i, j);
        dfs(i, j - 1, i, j, i, j);
        int tmp = 0;
        for (int k = 0; k < (h); k++)
          for (int l = 0; l < (w); l++) {
            tmp = max(tmp, dist[k][l]);
            dist[k][l] = 0;
          }
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans << endl;
}
