#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int oo = 1e9 + 7;
const int mod = 1e9 + 7;
const double PI = acos(-1);
bitset<500> vis;
vector<vector<char>> mat(20, vector<char>(20));
int w, h, adj[440][440] = {}, v;
void init() {
  for (int i = 0; i <= v; i++) {
    for (int j = 0; j <= v; j++) {
      adj[i][j] = oo;
    }
  }
}
int floyd() {
  for (int k = 0; k < v; k++) {
    for (int i = 0; i < v; i++) {
      for (int j = 0; j < v; j++) {
        adj[i][j] = min(adj[i][k] + adj[k][j], adj[i][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < v; i++) {
    for (int j = 0; j < v; j++) {
      if (adj[i][j] == oo) continue;
      if (j > i) break;
      ans = max(ans, adj[i][j]);
    }
  }
  return ans;
}
int main() {
  char mat[20][20];
  cin >> h >> w;
  v = h * w;
  init();
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> mat[i][j];
      if (i > 0 and mat[i][j] == mat[i - 1][j] and mat[i][j] == '.') {
        int a = (i * w) + j, b = ((i - 1) * w) + j;
        adj[a][b] = 1;
        adj[b][a] = 1;
      }
      if (j > 0 and mat[i][j] == mat[i][j - 1] and mat[i][j] == '.') {
        int a = (i * w) + j, b = (i * w) + (j - 1);
        adj[a][b] = 1;
        adj[b][a] = 1;
      }
    }
  }
  cout << floyd() << endl;
  return 0;
}
