#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;
int been[30][30];
char g[30][30];
int res = 0;
int h, w;
void bfs(int i, int j) {
  been[i][j] = 1;
  queue<pair<int, int> > q;
  q.push({i, j});
  int curr = -1;
  while (q.size() > 0) {
    queue<pair<int, int> > next;
    while (q.size() > 0) {
      auto p = q.front();
      q.pop();
      for (int ii = p.first - 1; ii <= p.first + 1; ii++) {
        for (int jj = p.second - 1; jj <= p.second + 1; jj++) {
          if (ii != p.first && jj != p.second) continue;
          if (ii <= 0 || ii > h) continue;
          if (jj <= 0 || jj > w) continue;
          if (been[ii][jj] || g[ii][jj] == '#') continue;
          been[ii][jj] = 1;
          next.push({ii, jj});
        }
      }
    }
    curr++;
    q = next;
  }
  res = max(res, curr);
}
void solve() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> g[i][j];
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      memset(been, 0, sizeof(been));
      bfs(i, j);
    }
  }
  cout << res << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
