#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ",";
    os << *it;
  }
  return os << "}";
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& v) {
  os << "{";
  os << v.first << ", " << v.second;
  return os << "}";
}
using point = complex<double>;
using ll = long long;
int solve(vector<vector<bool>>& wall, int sy, int sx) {
  array<int, 4> dx = {-1, 0, 1, 0};
  array<int, 4> dy = {0, -1, 0, 1};
  int h = wall.size();
  int w = wall[0].size();
  const int INF = 10000000;
  vector<vector<int>> step(h, vector<int>(w, INF));
  step[sy][sx] = 0;
  queue<pair<int, int>> que;
  int curstep = 1;
  for (int i = 0; i < 4; i++) {
    int ny = sy + dy[i];
    int nx = sx + dx[i];
    if (0 <= ny && ny < h && 0 <= nx && nx < w && !wall[ny][nx]) {
      que.push({ny, nx});
    }
  }
  while (!que.empty()) {
    queue<pair<int, int>> nex;
    while (!que.empty()) {
      auto p = que.front();
      que.pop();
      int y = p.first;
      int x = p.second;
      if (step[y][x] != INF) continue;
      step[y][x] = curstep;
      for (int i = 0; i < 4; i++) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (0 <= ny && ny < h && 0 <= nx && nx < w && !wall[ny][nx]) {
          nex.push({ny, nx});
        }
      }
    }
    curstep++;
    que = nex;
  }
  int ret = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (!wall[y][x]) ret = max(ret, step[y][x]);
    }
  }
  return ret;
}
int my_main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> wall(h, vector<bool>(w));
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      wall[i][j] = s[j] == '#';
    }
  }
  int ret = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ret = max(ret, solve(wall, i, j));
    }
  }
  cout << ret << endl;
  return 0;
}
int main(int argc, char** argv) { return my_main(argc, argv); }
