#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m;
char g[22][22];
bool ch(int i, int j) {
  if (i > 0 && j > 0 && i <= n && j <= m) return true;
  return false;
}
int bfs(int i, int j) {
  bool vstd[n + 1][m + 1];
  memset(vstd, false, sizeof vstd);
  int dst[n + 1][m + 1];
  for (int z = 0; z <= n; z++) {
    for (int zz = 0; zz <= m; zz++) dst[z][zz] = 1e9;
  }
  dst[i][j] = 0;
  queue<pair<int, int> > q;
  q.push({i, j});
  while (q.size()) {
    int ndx = q.front().first, ndy = q.front().second;
    q.pop();
    if (vstd[ndx][ndy]) continue;
    vstd[ndx][ndy] = true;
    if (ch(ndx + 1, ndy) && g[ndx + 1][ndy] == '.') {
      if (dst[ndx + 1][ndy] > dst[ndx][ndy] + 1) {
        dst[ndx + 1][ndy] = dst[ndx][ndy] + 1;
        q.push({ndx + 1, ndy});
      }
    }
    if (ch(ndx - 1, ndy) && g[ndx - 1][ndy] == '.') {
      if (dst[ndx - 1][ndy] > dst[ndx][ndy] + 1) {
        dst[ndx - 1][ndy] = dst[ndx][ndy] + 1;
        q.push({ndx - 1, ndy});
      }
    }
    if (ch(ndx, ndy + 1) && g[ndx][ndy + 1] == '.') {
      if (dst[ndx][ndy + 1] > dst[ndx][ndy] + 1) {
        dst[ndx][ndy + 1] = dst[ndx][ndy] + 1;
        q.push({ndx, ndy + 1});
      }
    }
    if (ch(ndx, ndy - 1) && g[ndx][ndy - 1] == '.') {
      if (dst[ndx][ndy - 1] > dst[ndx][ndy] + 1) {
        dst[ndx][ndy - 1] = dst[ndx][ndy] + 1;
        q.push({ndx, ndy - 1});
      }
    }
  }
  int mx = 0;
  for (int z = 1; z <= n; z++)
    for (int zz = 1; zz <= m; zz++) {
      if (dst[z][zz] != 1e9) mx = max(mx, dst[z][zz]);
    }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> g[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans;
  return 0;
}
