#include <bits/stdc++.h>
using namespace std;
void search(int *m, int *r, int h, int w, int c, int g, int d) {
  if (r[c] > d) {
    r[c] = d;
  }
  if (c == g || r[g] <= d + 1) {
    return;
  }
  if (c % w != (w - 1) && m[c + 1] && r[c + 1] > d + 1) {
    search(m, r, h, w, c + 1, g, d + 1);
  }
  if (c % w != 0 && m[c - 1] && r[c - 1] > d + 1) {
    search(m, r, h, w, c - 1, g, d + 1);
  }
  if ((c - w) >= 0 && m[c - w] && r[c - w] > d + 1) {
    search(m, r, h, w, c - w, g, d + 1);
  }
  if ((c + w) < h * w && m[c + w] && r[c + w] > d + 1) {
    search(m, r, h, w, c + w, g, d + 1);
  }
}
int main() {
  int h, w;
  cin >> h >> w;
  int m[h * w];
  for (int i = 0; i < h; i++) {
    string line;
    cin >> line;
    for (int j = 0; j < w; j++) {
      if (line[j] == '.') {
        m[i * w + j] = 1;
      } else {
        m[i * w + j] = 0;
      }
    }
  }
  int r[h * w];
  int max = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = i + 1; j < h * w; j++) {
      for (int k = 0; k < h * w; k++) {
        r[k] = h * w + 1;
      }
      if (m[i] == 0 || m[j] == 0) {
        continue;
      }
      search(m, r, h, w, i, j, 0);
      if (r[j] > max) {
        max = r[j];
      }
    }
  }
  cout << max << endl;
  return 0;
}
