#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int bfs(const vector<string>& field, int x, int y) {
  int h = field.size();
  int w = field[0].size();
  vector<vector<int>> dist(h, vector<int>(w, -1));
  queue<pair<int, int>> q;
  q.push({x, y});
  dist[x][y] = 0;
  int ans = 0;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    ans = max(ans, dist[x][y]);
    q.pop();
    for (int dir = 0; dir < 4; dir++) {
      int nx = x + dx[dir];
      int ny = y + dy[dir];
      if (field[nx][ny] == '#' || nx < 0 || ny < 0 || nx >= h || ny >= w)
        continue;
      if (dist[nx][ny] == -1) {
        dist[nx][ny] = dist[x][y] + 1;
        q.push({nx, ny});
      }
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> field(h);
  for (int i = 0; i < (int)(h); i++) {
    cin >> field[i];
  }
  int ans = 0;
  for (int x = 0; x < (int)(h); x++)
    for (int y = 0; y < (int)(w); y++) {
      if (field[x][y] == '#') continue;
      ans = max(ans, bfs(field, x, y));
    }
  cout << ans << endl;
}
