#include <bits/stdc++.h>
using namespace std;
int h, w;
pair<int, int> p;
queue<pair<int, int>> q;
int f(vector<vector<int>>& t) {
  p = q.front();
  int i = p.first, j = p.second;
  int n = t[i][j] + 1, f = 0;
  if (i - 1 >= 0 && t[i - 1][j] == 0) {
    t[i - 1][j] = n;
    p.first = i - 1;
    p.second = j;
    q.push(p);
    f = 1;
  }
  if (i + 1 < h && t[i + 1][j] == 0) {
    t[i + 1][j] = n;
    p.first = i + 1;
    p.second = j;
    q.push(p);
    f = 1;
  }
  if (j - 1 >= 0 && t[i][j - 1] == 0) {
    t[i][j - 1] = n;
    p.first = i;
    p.second = j - 1;
    q.push(p);
    f = 1;
  }
  if (j + 1 < w && t[i][j + 1] == 0) {
    t[i][j + 1] = n;
    p.first = i;
    p.second = j + 1;
    q.push(p);
    f = 1;
  }
  q.pop();
  return (f ? n : n - 1);
}
int main() {
  string u;
  char c;
  int ans = 0;
  cin >> h >> w;
  vector<vector<int>> s(h, vector<int>(w, 0)), t;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c;
      if (c == '.')
        s[i][j] = 0;
      else
        s[i][j] = -1;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == 0) {
        t = s;
        p.first = i, p.second = j;
        q.push(p);
        while (q.empty() == 0) {
          ans = max(ans, f(t));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
