#include <bits/stdc++.h>

using namespace std;

const int inf = 1 << 29;
char c[20][21];
int was[20][20];
int di[] = {0, 0, 1, -1};
int dj[] = {1, -1, 0, 0};

int main() {
  int n, m; cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < m; ++j) {
      if(c[i][j] == '#') continue;
      memset(was, -1, sizeof was);
      was[i][j] = 0;
      queue<pair<int, int> > Q;
      Q.emplace(i, j);
      while(Q.size()) {
        auto top = Q.front();
        Q.pop();
        for(int k = 0; k < 4; ++k) {
          int ii = top.first + di[k];
          int jj = top.second + dj[k];
          if(ii < 0 || ii >= n || jj < 0 || jj >= m || c[ii][jj] == '#' || was[ii][jj] != -1) continue;
          was[ii][jj] = was[top.first][top.second] + 1;
          ans = max(ans, was[ii][jj]);
          Q.emplace(ii, jj);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
