#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<vector<char>>;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1001001001;
int main() {
  int h, w;
  cin >> h >> w;
  Field F(h, vector<char>(w));
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) cin >> F[i][j];
  int ans = 0;
  for (int j = 0; j < (h); ++j)
    for (int k = 0; k < (w); ++k) {
      queue<pair<int, int>> q;
      vector<vector<int>> dist(h, vector<int>(w, INF));
      q.push({j, k});
      dist[j][k] = 0;
      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        for (int i = 0; i < (4); ++i) {
          int y = p.first + dy[i];
          int x = p.second + dx[i];
          if (y < 0 || y >= h || x < 0 || x >= w) continue;
          if (F[y][x] == '#') continue;
          if (dist[y][x] != INF) continue;
          dist[y][x] = dist[p.first][p.second] + 1;
          ans = max(ans, dist[y][x]);
          q.push({y, x});
        }
      }
    }
  cout << ans << endl;
  return 0;
}
