#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
bool prime(int n) {
  if (n == 0 || n == 1) return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
const long long power(int n, int k) {
  long long t = 1;
  for (int i = 0; i < (int)(k); i++) t *= n;
  return t;
}
const string turn2(int n) {
  string s = "";
  while (n != 0) {
    s += (char)(n % 2 + '0');
    n /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
const string turn16(int n) {
  string s = "";
  while (n != 0) {
    if (n % 16 > 9)
      s += (char)('A' + n % 16 - 10);
    else
      s += (char)('0' + n % 16);
    n /= 16;
  }
  reverse(s.begin(), s.end());
  return s;
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m;
queue<pair<long long, long long> > q;
int d[22][22];
bool dist[22][22];
string s[22];
bool good(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
void bfs(int x, int y) {
  d[x][y] = 0;
  dist[x][y] = 1;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    int cx = q.front().first, cy = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int xx = cx + dx[i], yy = cy + dy[i];
      if (good(xx, yy) && s[xx][yy] != '#')
        if (!dist[xx][yy]) {
          d[xx][yy] = d[cx][cy] + 1;
          dist[xx][yy] = 1;
          q.push(make_pair(xx, yy));
        }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) cin >> s[i];
  int maxn = 0;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) {
      memset(d, 0, sizeof(d));
      memset(dist, 0, sizeof(dist));
      bfs(i, j);
      for (int i = 0; i < (int)(n); i++) {
        for (int j = 0; j < (int)(m); j++) {
          maxn = max(maxn, d[i][j]);
        }
      }
    }
  cout << maxn << endl;
  return 0;
}
