#include <bits/stdc++.h>
using ll = long long;
using lli = long long int;
lli h, w;
std::vector<std::string> vec;
std::vector<std::vector<lli>> visited;
std::string s;
std::vector<int> x_s;
std::vector<int> y_s;
int main() {
  lli ans = 0;
  x_s = {0, 0, 1, -1};
  y_s = {1, -1, 0, 0};
  std::cin >> h >> w;
  vec.assign(h, "a");
  for (int i = 0; i < h; i++) {
    std::cin >> s;
    vec[i] = s;
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (vec[i][j] == '.') {
        visited.assign(h, std::vector<lli>(w, 0));
        std::queue<std::vector<lli>> q;
        q.push({i, j, 0});
        while (!q.empty()) {
          auto point = q.front();
          lli x = point[1];
          lli y = point[0];
          if (point[2] > ans) {
            ans = point[2];
          }
          visited[y][x] = 1;
          for (int k = 0; k < 4; k++) {
            if (y + y_s[k] >= 0 && x + x_s[k] >= 0 && y + y_s[k] < h &&
                x + x_s[k] < w && vec[y + y_s[k]][x + x_s[k]] != '#' &&
                visited[y + y_s[k]][x + x_s[k]] != 1) {
              q.push({y + y_s[k], x + x_s[k], point[2] + 1});
            }
          }
          q.pop();
        }
      }
    }
  }
  std::cout << ans << std::endl;
}
