#include <bits/stdc++.h>
using namespace std;
template <typename T>
void vdeb(vector<T> &da) {
  int size = da.size();
  for (int i = 0; i < size; i++) {
    if (i == size - 1) {
      cout << da[i] << endl;
    } else {
      cout << da[i] << ' ';
    }
  }
}
template <typename T>
void vvdeb(vector<T> &da) {
  int size = da.size();
  for (int i = 0; i < size; i++) {
    vdeb(da[i]);
  }
}
int h, w;
vector<vector<int>> li = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
void bfs(vector<string> &da, vector<vector<int>> &co, int s, int t) {
  queue<pair<int, long long>> q;
  q.push(make_pair(s, t));
  co[s][t] = 1;
  while (!q.empty()) {
    pair<int, long long> now = q.front();
    q.pop();
    for (int i = (0); i < (int)(4); i++) {
      if (0 <= now.first + li[i][0] && now.first + li[i][0] < h &&
          now.second + li[i][1] >= 0 && now.second + li[i][1] < w &&
          co[now.first + li[i][0]][now.second + li[i][1]] == 0 &&
          da[now.first + li[i][0]][now.second + li[i][1]] == '.') {
        q.push(make_pair(now.first + li[i][0], now.second + li[i][1]));
        co[now.first + li[i][0]][now.second + li[i][1]] =
            co[now.first][now.second] + 1;
      }
    }
  }
  return;
}
int MM(vector<vector<int>> &co) {
  int s = 0, t = 0;
  for (int i = (0); i < (int)(h); i++) {
    for (int j = (0); j < (int)(w); j++) {
      if (co[i][j] > co[s][t]) {
        s = i;
        t = j;
      }
    }
  }
  return co[s][t];
}
int main() {
  cin >> h >> w;
  vector<string> da(h);
  for (int i = (0); i < (int)(h); i++) {
    cin >> da[i];
  }
  int ans = 0;
  for (int i = (0); i < (int)(h); i++) {
    for (int j = (0); j < (int)(w); j++) {
      vector<vector<int>> co(h, vector<int>(w));
      bfs(da, co, i, j);
      ans = max(ans, MM(co));
    }
  }
  cout << ans - 1 << endl;
}
