#include <bits/stdc++.h>
using namespace std;
long long h, w;
const long long INF = -10000;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
long long si, sj;
long long di, dj;
char maze[20][20];
long long dist[20][20];
int main() {
  cin >> h >> w;
  for (long long i = 0; i < (h); ++i)
    for (long long j = 0; j < (w); ++j) {
      cin >> maze[i][j];
    }
  long long ans = 0;
  for (long long si = 0; si < (h); ++si)
    for (long long sj = 0; sj < (w); ++sj) {
      {
        for (long long i = 0; i < (h); ++i)
          for (long long j = 0; j < (w); ++j) {
            { dist[i][j] = INF; }
          }
        queue<pair<long long, long long> > q;
        auto update = [&](long long i, long long j, long long x) {
          if (dist[i][j] != INF) return;
          dist[i][j] = x;
          q.push(pair<long long, long long>(i, j));
        };
        update(si, sj, 0);
        while (!q.empty()) {
          pair<long long, long long> p = q.front();
          q.pop();
          for (long long u = 0; u < (4); ++u) {
            long long nexti = p.first + dx[u], nextj = p.second + dy[u];
            if (nexti < 0 || nexti >= h || nextj < 0 || nextj >= w) {
              continue;
            }
            if (maze[nexti][nextj] == '#') {
              continue;
            }
            update(nexti, nextj, dist[p.first][p.second] + 1);
          }
        }
        for (long long i = 0; i < (h); ++i)
          for (long long j = 0; j < (w); ++j) {
            ans = max(ans, dist[i][j]);
          }
      }
    }
  cout << ans;
}
