#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
const int MX = 25;
bool vis[MX][MX];
int cnt[MX][MX];
int dx[] = {+1, -1, +0, +0};
int dy[] = {+0, -0, +1, -1};
vector<string> v;
int row, col;
int mx = 0;
void bfs(pair<int, int> source) {
  int i;
  queue<pair<int, int> > q;
  q.push(source);
  vis[source.first][source.second] = 1;
  while (!q.empty()) {
    pair<int, int> nd = q.front();
    q.pop();
    for (i = 0; i < 4; i++) {
      int x = nd.first + dx[i];
      int y = nd.second + dy[i];
      if (x >= 0 && x < row && y >= 0 && y < col && v[x][y] == '.' &&
          !vis[x][y]) {
        q.push({x, y});
        vis[x][y] = 1;
        cnt[x][y] = cnt[nd.first][nd.second] + 1;
      }
    }
  }
}
void fnd() {
  int i, j;
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) {
      mx = max(cnt[i][j], mx);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, j;
  cin >> row >> col;
  for (i = 0; i < row; i++) {
    string str;
    cin >> str;
    v.push_back(str);
  }
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) {
      memset(vis, 0, sizeof(vis));
      memset(cnt, 0, sizeof(cnt));
      bfs({i, j});
      fnd();
    }
  }
  cout << mx << "\n";
  return 0;
}
