#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<vector<T>> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
vector<vector<int>> grid_bfs(vector<string>& s, int sx, int sy) {
  const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};
  vector<vector<int>> min_cost(s.size(), vector<int>(s[0].size(), -1));
  queue<pair<int, int>> que;
  for (int i = 0; i < (int)s.size(); i++) {
    for (int j = 0; j < (int)s[i].size(); j++) {
      if (i == sx && j == sy) {
        que.emplace(i, j);
        min_cost[i][j] = 0;
      }
    }
  }
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + vx[i], ny = p.second + vy[i];
      if (nx < 0 || ny < 0 || ny >= (int)s[0].size() || nx >= (int)s.size())
        continue;
      if (min_cost[nx][ny] != -1) continue;
      if (s[nx][ny] == '#') continue;
      min_cost[nx][ny] = min_cost[p.first][p.second] + 1;
      que.emplace(nx, ny);
    }
  }
  return min_cost;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long 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 sx = 0; sx < (int)H; ++sx) {
    for (int sy = 0; sy < (int)W; ++sy) {
      auto tmp = grid_bfs(S, sx, sy);
      for (int tx = 0; tx < (int)H; ++tx) {
        for (int ty = 0; ty < (int)W; ++ty) {
          res = max(res, tmp[tx][ty]);
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
