#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
const int ININF = 1000000;
int main() {
  string hw[22];
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> hw[i];
  }
  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int d[22][22];
      for (int t = 0; t < H; t++) {
        for (int s = 0; s < W; s++) {
          d[t][s] = ININF;
        }
      }
      d[i][j] = 0;
      queue<pair<int, int>> que;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        pair<int, int> tmp = que.front();
        que.pop();
        int a = tmp.first;
        int b = tmp.second;
        int count = d[a][b];
        if (a != 0 && hw[a - 1][b] == '.' && d[a - 1][b] > count + 1) {
          d[a - 1][b] = count + 1;
          que.push(make_pair(a - 1, b));
        }
        if (b != 0 && hw[a][b - 1] == '.' && d[a][b - 1] > count + 1) {
          d[a][b - 1] = count + 1;
          que.push(make_pair(a, b - 1));
        }
        if (a != H - 1 && hw[a + 1][b] == '.' && d[a + 1][b] > count + 1) {
          d[a + 1][b] = count + 1;
          que.push(make_pair(a + 1, b));
        }
        if (b != W - 1 && hw[a][b + 1] == '.' && d[a][b + 1] > count + 1) {
          d[a][b + 1] = count + 1;
          que.push(make_pair(a, b + 1));
        }
      }
      int max = 0;
      for (int t = 0; t < H; t++) {
        for (int s = 0; s < W; s++) {
          if (d[t][s] != ININF && d[t][s] > max) {
            max = d[t][s];
          }
        }
      }
      if (res < max) {
        res = max;
      }
    }
  }
  cout << res << endl;
}
