#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<vector<char> > s;
vector<vector<int> > cost;
int bfs(int starty, int startx) {
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  queue<pair<int, int> > que;
  que.push(make_pair(starty, startx));
  cost[starty][startx] = 0;
  int M = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < (4); i++) {
      M = max(M, cost[p.first][p.second]);
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if (s[ny][nx] == '#') continue;
      if (cost[ny][nx] != -1) continue;
      cost[ny][nx] = cost[p.first][p.second] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  return M;
}
int main() {
  cin >> h >> w;
  s = vector<vector<char> >(h, vector<char>(w));
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) cin >> s[i][j];
  cost = vector<vector<int> >(h, vector<int>(w, -1));
  int ans = 0;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      ans = max(ans, bfs(i, j));
      cost = vector<vector<int> >(h, vector<int>(w, -1));
    }
  cout << ans << endl;
}
