#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 222;
vector<pair<int, int>> moves = {make_pair(0, 1), make_pair(1, 0),
                                make_pair(0, -1), make_pair(-1, 0)};
int n, m;
string g[maxn];
int dist[maxn][maxn];
struct node {
  int x, y, d;
};
int ans;
void bfs(int i, int j) {
  memset(dist, -1, sizeof dist);
  queue<node> q;
  q.push({i, j, 0});
  while (q.size()) {
    node at = q.front();
    q.pop();
    int d = at.d;
    for (auto mo : moves) {
      int x = at.x + mo.first;
      int y = at.y + mo.second;
      if (x < 0 || x >= n || y < 0 || y >= m || g[x][y] == '#' ||
          dist[x][y] != -1)
        continue;
      dist[x][y] = d + 1;
      q.push({x, y, d + 1});
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(dist[i][j], ans);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '#') continue;
      bfs(i, j);
    }
  }
  out(ans);
  return 0;
}
