#include <bits/stdc++.h>
using namespace std;
class DMazeMaster {
 public:
  int64_t dfs(int64_t x, int64_t y, int64_t cost) {
    if (x < 0 || x >= h || y < 0 || y >= w) {
      return -1;
    } else if (maze[x][y] == '#') {
      return -1;
    }
    if (distance[x][y] == -1) {
      distance[x][y] = cost;
    } else if (distance[x][y] < cost) {
      return -1;
    } else {
      distance[x][y] = cost;
    }
    for (const auto &p : move) {
      dfs(x + p.first, y + p.second, cost + 1);
    }
    int64_t ret = 0;
    for (const auto &item : distance) {
      for (const auto &item2 : item) {
        ret = max(item2, ret);
      }
    }
    return ret;
  }
  void solve(std::istream &cin, std::ostream &cout) {
    cin >> h >> w;
    maze.resize(h);
    for (int i = 0; i < h; ++i) {
      cin >> maze[i];
    }
    move.emplace_back(1, 0);
    move.emplace_back(-1, 0);
    move.emplace_back(0, 1);
    move.emplace_back(0, -1);
    int64_t ans = 0;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        distance.clear();
        distance.resize(h, vector<int64_t>(w, -1));
        ans = max(ans, dfs(i, j, 0));
      }
    }
    cout << ans << endl;
  }
  int64_t h, w;
  vector<string> maze;
  vector<vector<int64_t>> distance;
  vector<pair<int, int>> move;
};
int main() {
  DMazeMaster solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
