#include <bits/stdc++.h>
using namespace std;
int fx4[] = {1, -1, 0, 0};
int fy4[] = {0, 0, 1, -1};
int Kfx[] = {-2, -2, 2, 2, 1, 1, -1, -1};
int Kfy[] = {1, -1, 1, -1, 2, -2, 2, -2};
int fx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
int fy8[] = {0, 1, -1, 1, -1, 0, 1, -1};
long long int BM(long long int a, long long int b, long long int m) {
  if (b == 0) return 1;
  long long int x = BM(a, b / 2, m);
  x = ((x % m) * (x % m)) % m;
  if (b % 2) x = ((x % m) * (a % m)) % m;
  return x;
}
int row, col;
int vis[22][22];
int mat[22][22];
int dis[22][22];
int M = 0;
int fx[] = {-1, 1, 0, 0};
int fy[] = {0, 0, -1, 1};
void bfs(int i, int j) {
  memset(dis, 0, sizeof(dis));
  memset(vis, 0, sizeof(vis));
  queue<pair<int, int> > q;
  q.push(pair<int, int>(i, j));
  dis[i][j] = 0;
  while (!q.empty()) {
    pair<int, int> top = q.front();
    q.pop();
    for (int k = 0; k < 4; k++) {
      int kx = top.first + fx[k];
      int ky = top.second + fy[k];
      if (kx >= 0 and ky >= 0 and kx < row and ky < col and mat[kx][ky] == 1 and
          vis[kx][ky] == 0) {
        vis[kx][ky] = 1;
        dis[kx][ky] = dis[top.first][top.second] + 1;
        M = max(M, dis[kx][ky]);
        q.push(pair<int, int>(kx, ky));
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> row >> col;
  for (int i = 0; i < row; i++) {
    string a;
    cin >> a;
    for (int j = 0; j < a.size(); j++) {
      if (a[j] == '#')
        mat[i][j] = 0;
      else
        mat[i][j] = 1;
    }
  }
  for (int i = 0; i < row; i++) {
    for (int j = 0; j < col; j++) {
      if (mat[i][j] == 1) bfs(i, j);
    }
  }
  cout << M << endl;
}
