#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
const int xp[] = {1, 0, -1, 0};
const int yp[] = {0, 1, 0, -1};
bool l[maxn][maxn];
void scan(int &a) {
  a = 0;
  char c = getchar();
  while (c >= '0' && c <= '9') {
    a *= 10;
    a += c - '0';
    c = getchar();
  }
}
bool bio[maxn][maxn];
int n, m;
int bfs(int x, int y) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      bio[i][j] = 0;
    }
  }
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  int sol = -1;
  int sz;
  pair<int, int> p;
  int xs, ys;
  while (!q.empty()) {
    sol++;
    sz = q.size();
    for (int i = 0; i < sz; i++) {
      p = q.front();
      q.pop();
      for (int j = 0; j < 4; j++) {
        xs = p.first + xp[j];
        ys = p.second + yp[j];
        if (xs < n && ys < m && xs > -1 && ys > -1 && l[xs][ys] &&
            !bio[xs][ys]) {
          bio[xs][ys] = 1;
          q.push(make_pair(xs, ys));
        }
      }
    }
  }
  return sol;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  scan(n);
  scan(m);
  char c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c = getchar();
      if (c == '.') {
        l[i][j] = 1;
      }
    }
    getchar();
  }
  int sol = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (l[i][j]) {
        sol = max(sol, bfs(i, j));
      }
    }
  }
  cout << sol << '\n';
  return 0;
}
