#include <bits/stdc++.h>
using namespace std;
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
inline int readInt() {
  int x;
  scanf("%d", &x);
  return x;
}
const double EPS = 1E-8;
const int INF = 2147483647;
const int dxy[5] = {-1, 0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> v;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      queue<pair<int, int>> q;
      vector<vector<int>> dist(H, vector<int>(W, -1));
      dist[i][j] = 0;
      q.push(make_pair(i, j));
      while (q.size()) {
        pair<int, int> p = q.front();
        q.pop();
        int y = p.first, x = p.second;
        for (int k = 0; k < 4; k++) {
          int ny = y + dxy[k], nx = x + dxy[k + 1];
          if (ny >= 0 && ny < H && nx >= 0 && nx < W && dist[ny][nx] == -1 &&
              v[ny][nx] == '.') {
            dist[ny][nx] = dist[y][x] + 1;
            q.push({ny, nx});
          }
        }
      }
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          ans = max(ans, dist[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
