#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
long long fact(long long n) {
  long long res = 1;
  for (long long i = 2; i <= n; ++i) res = res * i;
  return res;
}
long long nCr(long long n, long long r) {
  return (fact(n) / fact(n - r) * fact(r));
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
const int inf = 1 << 30;
int H, W;
int ans;
int maze[50][50];
bool visited[50][50];
char S[50][50];
void printMaze() {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << maze[i][j] << " ";
    }
    cout << endl;
  }
  cout << "------" << endl;
}
void init() {
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 50; j++) {
      maze[i][j] = inf;
      visited[i][j] = false;
    }
  }
}
void search(int xx, int yy, int dist) {
  maze[yy][xx] = min(maze[yy][xx], dist);
  queue<pair<int, int> > q;
  q.push(pair<int, int>(yy, xx));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.second, y = p.first;
    visited[y][x] = true;
    for (int i = 0; i < (int)(4); ++i) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= H) continue;
      if (nx < 0 || nx >= W) continue;
      if (S[ny][nx] == '#') continue;
      if (visited[ny][nx]) continue;
      q.push(pair<int, int>(ny, nx));
      maze[ny][nx] = min(maze[ny][nx], maze[y][x] + 1);
    }
  }
}
int solve(pair<int, int> start, pair<int, int> end) {
  maze[start.second][start.first] = 0;
  search(start.second, start.first, 0);
  return maze[end.first][end.second];
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  vector<pair<int, int> > terms;
  for (int i = 0; i < (int)(H); ++i)
    for (int j = 0; j < (int)(W); ++j) {
      cin >> S[i][j];
      if (S[i][j] == '.') terms.push_back(pair<int, int>(i, j));
    }
  int ans = 0;
  for (int i = 0; i < terms.size(); i++) {
    for (int j = i + 1; j < terms.size(); j++) {
      pair<int, int> start = terms[i], end = terms[j];
      init();
      int ansCand = solve(start, end);
      if (ans == inf) continue;
      ans = max(ans, ansCand);
    }
  }
  cout << ans << endl;
  return 0;
}
