#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
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;
}
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> field(H);
  for (int i = 0; i < (int)(H); i++) cin >> field.at(i);
  int max = 0;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      vector<vector<int>> dist(H, vector<int>(W, -1));
      queue<pair<int, int>> que;
      que.push(make_pair(x, y));
      dist.at(y).at(x) = 0;
      int tempMax = 0;
      while (!que.empty()) {
        pair<int, int> v = que.front();
        que.pop();
        int cx = v.first;
        int cy = v.second;
        for (int i = 0; i < 4; i++) {
          int nx = cx + dx.at(i);
          int ny = cy + dy.at(i);
          if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
          if (field.at(ny).at(nx) == '#') continue;
          if (dist.at(ny).at(nx) != -1) continue;
          dist.at(ny).at(nx) = dist.at(cy).at(cx) + 1;
          chmax(tempMax, dist.at(ny).at(nx));
          que.push(make_pair(nx, ny));
        }
      }
      chmax(max, tempMax);
    }
  }
  cout << max << endl;
}
