#include <bits/stdc++.h>
using namespace std;
class XY {
 public:
  long long x, y;
  XY() { x = y = 0; }
  XY(long long u, long long v) {
    x = u;
    y = v;
  }
};
template <typename T1, typename T2>
void chmin(T1 &first, T2 second) {
  if (first > second) first = second;
}
template <typename T1, typename T2>
void chmax(T1 &first, T2 second) {
  if (first < second) first = second;
}
template <typename T1, typename T2>
long long mypow(T1 first, T2 n) {
  if (n == 0) return 1;
  if (n == 1) return first;
  if (n % 2) return first * mypow(first, n - 1);
  long long tmp = mypow(first, n / 2);
  return tmp * tmp;
}
template <typename T>
int BS(vector<T> &V, int left, int right, T key) {
  int mid = (left + right) / 2;
  if (V[mid] <= key)
    left = mid;
  else
    right = mid;
  if (right - mid == 1)
    return left;
  else
    return BS(V, left, right, key);
}
long long comb(long long n, long long r) {
  long long res = 1;
  for (int i = 0; i < r; i++) {
    res *= n - i;
    res /= i + 1;
  }
  return res;
}
template <typename T>
T euclid(T first, T second) {
  if (second == 0)
    return first;
  else
    return euclid(second, first % second);
}
template <class T>
struct UFT {
  vector<int> par;
  vector<int> rank;
  vector<T> diff_weight;
  UFT(int n = 1, T w = 0) { init(n, w); }
  void init(int n = 1, T w = 0) {
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
      diff_weight[i] = w;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }
  bool unite(int x, int y, int w = 0) {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) {
      par[x] = y;
      diff_weight[x] = -w;
    } else {
      par[y] = x;
      diff_weight[y] = w;
      if (rank[x] == rank[y]) rank[x]++;
    }
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  T weight(int x) {
    root(x);
    return diff_weight[x];
  }
  T diff(int x, int y) { return weight(y) - weight(x); }
};
long long digit(long long N) { return log10(N) + 1; }
void Main() {
  int H, W;
  cin >> H >> W;
  vector<string> T(H);
  for (int i = 0; i < H; i++) cin >> T[i];
  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      vector<string> S = T;
      queue<vector<int>> que;
      que.push({i, j, 0});
      int cost = 0;
      while (!que.empty()) {
        vector<int> cur = que.front();
        que.pop();
        int x = cur[0];
        int y = cur[1];
        cost = cur[2];
        S[x][y] = '#';
        if (x > 0 && S[x - 1][y] == '.') que.push({x - 1, y, cost + 1});
        if (x < H - 1 && S[x + 1][y] == '.') que.push({x + 1, y, cost + 1});
        if (y > 0 && S[x][y - 1] == '.') que.push({x, y - 1, cost + 1});
        if (y < W - 1 && S[x][y + 1] == '.') que.push({x, y + 1, cost + 1});
      }
      chmax(res, cost);
    }
  }
  cout << res << endl;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);
  Main();
}
