#include <bits/stdc++.h>
using namespace std;
void Main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h * w);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int maxl = 0;
  for (int i = 0; i < h * w; i++) {
    vector<vector<int>> a(h, vector<int>(w, -1));
    queue<int> q;
    q.push(i);
    a[i / w][i % w] = 0;
    while (!q.empty()) {
      int j = q.front();
      q.pop();
      int x = j % w;
      int y = j / w;
      if (x - 1 >= 0 && s[y][x - 1] == '.' && a[y][x - 1] == -1) {
        a[y][x - 1] = a[y][x] + 1;
        q.push(y * w + (x - 1));
        maxl = max(maxl, a[y][x - 1]);
      }
      if (x + 1 < w && s[y][x + 1] == '.' && a[y][x + 1] == -1) {
        a[y][x + 1] = a[y][x] + 1;
        q.push(y * w + (x + 1));
        maxl = max(maxl, a[y][x + 1]);
      }
      if (y - 1 >= 0 && s[y - 1][x] == '.' && a[y - 1][x] == -1) {
        a[y - 1][x] = a[y][x] + 1;
        q.push((y - 1) * w + x);
        maxl = max(maxl, a[y - 1][x]);
      }
      if (y + 1 < h && s[y + 1][x] == '.' && a[y + 1][x] == -1) {
        a[y + 1][x] = a[y][x] + 1;
        q.push((y + 1) * w + x);
        maxl = max(maxl, a[y + 1][x]);
      }
    }
  }
  cout << maxl << endl;
}
int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  Main();
  return 0;
}
