#include <bits/stdc++.h>
using namespace std;
vector<int> xd{-1, 1, 0, 0};
vector<int> yd{0, 0, -1, 1};
int X, Y;
int bfs(vector<string>& b, int x, int y) {
  set<pair<int, int>> visited;
  queue<pair<pair<int, int>, int>> st;
  int maxD = 0;
  st.push(make_pair(make_pair(x, y), 0));
  while (!st.empty()) {
    auto now = st.front();
    st.pop();
    int depth = now.second;
    visited.insert(now.first);
    maxD = max(maxD, depth);
    for (int d = 0; d < 4; d++) {
      int tx = now.first.first + xd[d];
      int ty = now.first.second + yd[d];
      if (tx < 0 || tx >= X || ty < 0 || ty >= Y || b[ty][tx] == '#') {
        continue;
      }
      if (visited.count(make_pair(tx, ty)) > 0) {
        continue;
      }
      st.push(make_pair(make_pair(tx, ty), depth + 1));
    }
  }
  return maxD;
}
int main() {
  cin >> Y >> X;
  vector<string> b(Y);
  for (int y = 0; y < Y; y++) {
    cin >> b[y];
  }
  int maxD = 0;
  for (int y = 0; y < Y; y++) {
    for (int x = 0; x < X; x++) {
      maxD = max(maxD, bfs(b, x, y));
    }
  }
  cout << maxD;
  return 0;
}
