#include <bits/stdc++.h>
using namespace std;
char a[30][30] = {0};
long long int q[] = {1, -1, 0, 0};
long long int w[] = {0, 0, -1, 1};
long long int l;
long long int h;
long long int max1 = 0;
struct node {
  long long int x;
  long long int y;
};
int main() {
  cin >> h;
  cin >> l;
  for (long long int i = 1; i <= h; i++) {
    for (long long int j = 1; j <= l; j++) cin >> a[i][j];
  }
  for (long long int i = 1; i <= h; i++) {
    for (long long int j = 1; j <= l; j++) {
      if (a[i][j] == '#') continue;
      long long int vis[30][30] = {0};
      long long int sum1[30][30] = {0};
      queue<node> p;
      node r;
      r.x = i;
      r.y = j;
      p.push(r);
      while (!p.empty()) {
        node t = p.front();
        p.pop();
        for (long long int h1 = 0; h1 < 4; h1++) {
          long long z = t.x + q[h1];
          long long int x = t.y + w[h1];
          if (vis[z][x]) continue;
          if (z <= h && z > 0 && x <= l && x > 0 && a[z][x] == '.') {
            sum1[z][x] = sum1[t.x][t.y] + 1;
            node u;
            u.x = z;
            u.y = x;
            vis[z][x] = 1;
            p.push(u);
          }
        }
      }
      for (long long int i2 = 1; i2 <= h; i2++) {
        for (long long int j2 = 1; j2 <= l; j2++) {
          if (vis[i2][j2]) {
            max1 = max(max1, sum1[i2][j2]);
          }
        }
      }
    }
  }
  if (max1 == 1)
    cout << "0" << endl;
  else
    cout << max1 << endl;
  return 0;
}
