#include <bits/stdc++.h>
using namespace std;
int a[100010];
char s[111][111];
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int main() {
  int n, m;
  while (cin >> n >> m) {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%s", s[i]);
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (s[i][j] == '#') continue;
        queue<pair<pair<int, int>, int>> q;
        q.push(make_pair(make_pair(i, j), 0));
        int dis[22][22];
        for (int k = 0; k < 20; ++k) {
          for (int l = 0; l < 20; ++l) {
            dis[k][l] = 111;
          }
        }
        pair<pair<int, int>, int> tmp;
        while (!q.empty()) {
          tmp = q.front();
          q.pop();
          if (dis[tmp.first.first][tmp.first.second] <= tmp.second) {
            continue;
          }
          dis[tmp.first.first][tmp.first.second] = tmp.second;
          for (int k = 0; k < 4; ++k) {
            int x = tmp.first.first + dx[k];
            int y = tmp.first.second + dy[k];
            if (x < 0 || x >= n || y < 0 || y >= m) continue;
            if (s[x][y] == '.')
              q.push(make_pair(make_pair(x, y), tmp.second + 1));
          }
        }
        for (int k = 0; k < 20; ++k) {
          for (int l = 0; l < 20; ++l) {
            if (dis[k][l] < 111) {
              ans = max(ans, dis[k][l]);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
