#include <bits/stdc++.h>
using namespace std;
char a[25][25] = {0};
int q[] = {1, 0, 0, -1};
int w[] = {0, 1, -1, 0};
int l;
int h;
int max1 = 0;
struct node {
  int x;
  int y;
};
int main() {
  cin >> h;
  cin >> l;
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < l; j++) {
      if (a[i][j] == '#') continue;
      int vis[25][25] = {0};
      int sum1[25][25] = {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 (int h1 = 0; h1 < 4; h1++) {
          int z = t.x + q[h1];
          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 (int i2 = 0; i2 < h; i2++) {
        for (int j2 = 0; j2 < l; j2++) {
          if (vis[i2][j2]) {
            max1 = max(max1, sum1[i2][j2]);
          }
        }
      }
    }
  }
  cout << max1 << endl;
  return 0;
}
