#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9;
int main() {
  int h, w;
  cin >> h >> w;
  char m[h][w];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> m[i][j];
    }
  }
  int s = h * w;
  int d[500][500];
  for (int i = 0; i < s; ++i) {
    for (int j = 0; j < s; ++j) {
      d[i][j] = INF;
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (m[i][j] == '#') {
        continue;
      }
      int v = i * h + j;
      d[v][v] = 0;
      if (i + 1 < h && m[i + 1][j] == '.') {
        int vd = (i + 1) * h + j;
        d[v][vd] = 1;
        d[vd][v] = 1;
      }
      if (i - 1 >= 0 && m[i - 1][j] == '.') {
        int vd = (i - 1) * h + j;
        d[v][vd] = 1;
        d[vd][v] = 1;
      }
      if (j + 1 < w && m[i][j + 1] == '.') {
        int vd = i * h + j + 1;
        d[v][vd] = 1;
        d[vd][v] = 1;
      }
      if (j - 1 >= 0 && m[i][j - 1] == '.') {
        int vd = i * h + j - 1;
        d[v][vd] = 1;
        d[vd][v] = 1;
      }
    }
  }
  for (int k = 0; k < s; ++k) {
    for (int i = 0; i < s; ++i) {
      for (int j = 0; j < s; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < s; ++i) {
    for (int j = 0; j < s; ++j) {
      if (d[i][j] != INF) {
        mx = max(mx, d[i][j]);
      }
    }
  }
  cout << mx;
  return 0;
}
