#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (int)h; ++i) cin >> s[i];
  int res = 0;
  for (int i = 0; i < (int)h; ++i) {
    for (int j = 0; j < (int)w; ++j) {
      if (s[i][j] == '#') continue;
      for (int k = 0; k < (int)h; ++k) {
        for (int l = 0; l < (int)w; ++l) {
          if (s[k][l] == '#') continue;
          if (i == k && j == l) continue;
          pair<int, int> st, g;
          st.first = i, st.second = j, g.first = k, g.second = l;
          vector<vector<int> > maze(h, vector<int>(w, 500));
          queue<pair<int, int> > q;
          q.push(st);
          maze[st.first][st.second] = 0;
          bool reached = false;
          while (!q.empty()) {
            if (reached) break;
            int x, y;
            x = q.front().first, y = q.front().second;
            q.pop();
            for (int m = 0; m < (int)4; ++m) {
              int nx, ny;
              nx = x + dx[m], ny = y + dy[m];
              if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
              if (s[nx][ny] == '#') continue;
              maze[nx][ny] = maze[x][y] + 1;
              q.push(make_pair(nx, ny));
              if (nx == g.first && ny == g.second) {
                res = max(res, maze[nx][ny]);
                reached = true;
                break;
              }
            }
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
