#include <bits/stdc++.h>
using namespace std;
char s[25][25];
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
const int DIR = 4;
int bfs(int w, int h, int si, int sj) {
  queue<pair<int, int>> q;
  q.emplace(si, sj);
  int cnt = 0;
  vector<vector<bool>> vis(h, vector<bool>(w, false));
  while (!q.empty()) {
    int size = q.size();
    while (size--) {
      auto n = q.front();
      q.pop();
      int xs = n.first;
      int ys = n.second;
      if (vis[xs][ys]) continue;
      vis[xs][ys] = true;
      for (int i = 0; i < DIR; i++) {
        int dx = xs + dir[i][0];
        int dy = ys + dir[i][1];
        if (dx < 0 || dx >= w || dy < 0 || dy >= h || s[dx][dy] == '#' ||
            vis[dx][dy])
          continue;
        q.emplace(dx, dy);
      }
    }
    cnt++;
  }
  return cnt - 1;
}
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = std::max(ans, bfs(w, h, i, j));
    }
  }
  cout << ans;
}
