#include <bits/stdc++.h>
using namespace std;
int H, W;
char S[21][21];
int Number[21][21];
int d[401][401];
int main() {
  cin >> H >> W;
  int N = 0;
  for (int(i) = 0; (i) < (21); (i)++) {
    for (int(j) = 0; (j) < (21); (j)++) {
      Number[i][j] = -1;
    }
  }
  for (int(i) = 0; (i) < (401); (i)++) {
    for (int(j) = 0; (j) < (401); (j)++) {
      d[i][j] = 21474836;
    }
  }
  for (int(i) = 0; (i) < (H); (i)++) {
    for (int(j) = 0; (j) < (W); (j)++) {
      cin >> S[i][j];
      if (S[i][j] == '.') {
        Number[i][j] = N;
        N++;
      }
    }
  }
  int V = N;
  for (int(i) = 0; (i) < (H); (i)++) {
    for (int(j) = 0; (j) < (W); (j)++) {
      if (Number[i][j] >= 0) {
        if (Number[i][j + 1] >= 0) {
          d[Number[i][j]][Number[i][j + 1]] = 1;
          d[Number[i][j + 1]][Number[i][j]] = 1;
        }
        if (Number[i + 1][j] >= 0) {
          d[Number[i][j]][Number[i + 1][j]] = 1;
          d[Number[i + 1][j]][Number[i][j]] = 1;
        }
      }
    }
  }
  for (int k = 0; k < V; k++)
    for (int i = 0; i < V; i++)
      for (int j = 0; j < V; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        d[j][i] = d[i][j];
      }
  int max = 0;
  for (int(i) = 0; (i) < (V); (i)++) {
    for (int(j) = 0; (j) < (V); (j)++) {
      if (d[i][j] < 21474836 && d[i][j] > max) max = d[i][j];
    }
  }
  cout << max << endl;
  return 0;
}
