#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 100000000;
char maze[25][25];
int N, M;
int sx, sy;
int gx, gy;
vector<vector<int>> d(25, vector<int>(25));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(int sx, int sy) {
  queue<pair<int, int>> que;
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (M); ++j) {
      d[i][j] = INF;
    }
  }
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  int a = 0;
  int b = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (M); ++j) {
      if (d[i][j] != 100000000) ans = max(ans, d[i][j]);
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  int res = 0;
  for (int i = 0; i < (N); ++i) {
    cin >> maze[i];
  }
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (M); ++j) {
      res = max(bfs(i, j), res);
    }
  }
  cout << res << endl;
  return 0;
}
