#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int64_t infi = 1147483600;
const long long infl = 4e18 + 5;
const char EOL = '\n';
int calc(vector<vector<int>> s, int h, int w, int i, int j) {
  if (s[i][j] != 0) {
    return 0;
  }
  if (s[i + 1][j] + s[i][j + 1] + s[i - 1][j] + s[i][j - 1] > -2) {
    return 0;
  }
  if (s[i + 1][j] == 0 && s[i - 1][j] == 0) {
    return 0;
  }
  if (s[i][j + 1] == 0 && s[i][j - 1] == 0) {
    return 0;
  }
  vector<vector<int>> m(h + 2, vector<int>(w + 2, -1));
  set<pair<int, int>> q;
  q.insert(make_pair(i, j));
  m[i][j] = 0;
  int res = 0;
  while (!q.empty()) {
    auto iter = q.begin();
    int u = iter->first;
    int v = iter->second;
    q.erase(iter);
    if (s[u + 1][v] == 0 && (m[u + 1][v] == -1 || m[u + 1][v] > m[u][v] + 1)) {
      m[u + 1][v] = m[u][v] + 1;
      q.insert(make_pair(u + 1, v));
    }
    if (s[u][v + 1] == 0 && (m[u][v + 1] == -1 || m[u][v + 1] > m[u][v] + 1)) {
      m[u][v + 1] = m[u][v] + 1;
      q.insert(make_pair(u, v + 1));
    }
    if (s[u - 1][v] == 0 && (m[u - 1][v] == -1 || m[u - 1][v] > m[u][v] + 1)) {
      m[u - 1][v] = m[u][v] + 1;
      q.insert(make_pair(u - 1, v));
    }
    if (s[u][v - 1] == 0 && (m[u][v - 1] == -1 || m[u][v - 1] > m[u][v] + 1)) {
      m[u][v - 1] = m[u][v] + 1;
      q.insert(make_pair(u, v - 1));
    }
  }
  for (long long u = 0; u < h; ++u) {
    for (long long v = 0; v < w; ++v) {
      res = max(res, m[u + 1][v + 1]);
    }
  }
  return res;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> s(h + 2, vector<int>(w + 2, -1));
  for (int i = 0; i < h; ++i) {
    string in;
    cin >> in;
    for (int j = 0; j < w; ++j) {
      if (in[j] == '.') {
        s[i + 1][j + 1] = 0;
      }
    }
  }
  int res = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int ret = calc(s, h, w, i + 1, j + 1);
      if (res < ret) res = ret;
    }
  }
  cout << res << endl;
}
