#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Grid {
  Grid(int h, int w) : h(h), w(w), st(w + 1), v(h * st, -1) {}
  void bfs() {
    queue<int> q;
    char s[21];
    for (int i = 0; i < h; i++) {
      cin >> s;
      for (int j = 0; j < w; j++) {
        if (s[j] == '.') {
          v[st * i + j] = 0;
        }
      }
    }
    int r = 0;
    for (int i1 = 0; i1 < h; i1++) {
      for (int j1 = 0; j1 < w; j1++) {
        if (v[st * i1 + j1] < 0) continue;
        for (int i = 0; i < h; i++) {
          for (int j = 0; j < w; j++) {
            if (v[st * i + j] >= 0) v[st * i + j] = 0;
          }
        }
        q.push(st * i1 + j1);
        while (!q.empty()) {
          int k = q.front();
          q.pop();
          for (auto d : {-st, -1, 1, st}) {
            int l = k + d;
            int i = l / st;
            int j = l % st;
            if (l < 0 || i == h || j == w) continue;
            if (v[l] == 0) {
              q.push(l);
              v[l] = v[k] + 1;
              r = max(r, v[l]);
            }
          }
        }
      }
    }
    cout << r << endl;
  }
  int h, w, st;
  vector<int> v;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  Grid g(h, w);
  g.bfs();
  return 0;
}
