#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long MOD = 1000000007;
const long long INF = MOD * MOD;
queue<pair<int, int> > que;
int w, h;
bool isV[501][501];
int m[501][501];
char s[501][501];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ans = 0;
void bfs() {
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (nx >= 0 and nx < w and ny >= 0 and ny < h and s[nx][ny] == '.' and
          isV[nx][ny] == false) {
        isV[nx][ny] = true;
        que.push(pair<int, int>(nx, ny));
        m[nx][ny] = m[p.first][p.second] + 1;
        ans = max(ans, m[nx][ny]);
      }
    }
  }
}
int main(void) {
  cin >> h >> w;
  cin.ignore();
  for (int i = 0; i < h; i++) {
    string st;
    getline(cin, st);
    for (int j = 0; j < w; j++) s[j][i] = st[j];
  }
  for (int k = 0; k < h; k++)
    for (int l = 0; l < w; l++) {
      if (s[k][l] == '.') {
        for (int i = 0; i < w; i++)
          for (int j = 0; j < h; j++) {
            m[i][j] = MOD;
            isV[i][j] = false;
          }
        isV[l][k] = true;
        m[l][k] = 0;
        que.push({l, k});
        bfs();
      }
    }
  cout << ans << "\n";
}
