#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
struct edge {
  int to, cost;
};
int h, w;
vector<int> a;
long long d[400][400];
void warshall_floyd(int n) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (d[i][k] == 2e9 || d[k][i] == 2e9) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  vector<string> s;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      d[i][j] = 2e9;
      if (i == j) d[i][j] = 0;
    }
  }
  for (int i = 0; i < h; i++) {
    string temp;
    cin >> temp;
    s.push_back(temp);
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        d[i * h + j][i * h + j] = 2e9;
        continue;
      }
      for (int k = 0; k < 4; k++) {
        if (i + dx[k] < 0 || j + dy[k] < 0 || i + dx[k] >= h || j + dy[k] >= w)
          continue;
        if (s[i + dx[k]][j + dy[k]] == '.') {
          d[i * h + j][(i + dx[k]) * h + j + dy[k]] = 1;
          d[(i + dx[k]) * h + j + dy[k]][i * h + j] = 1;
        }
      }
    }
  }
  warshall_floyd(h * w);
  long long ans = 0;
  for (int i = 0; i < 400; i++) {
    for (int j = 0; j < 400; j++) {
      if (d[i][j] > 450) continue;
      ans = max(d[i][j], ans);
    }
  }
  cout << ans << "\n";
}
