#include <bits/stdc++.h>
using namespace std;
int d[22][22][22][22];
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int ii = 0; ii < w; ii++)
      for (int j = 0; j < h; j++)
        for (int jj = 0; jj < w; jj++) d[i][ii][j][jj] = 1e8;
  string s[22];
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      if (i && s[i - 1][j] == '.') d[i][j][i - 1][j] = d[i - 1][j][i][j] = 1;
      if (j && s[i][j - 1] == '.') d[i][j][i][j - 1] = d[i][j - 1][i][j] = 1;
    }
  }
  for (int j = 0; j < h; j++)
    for (int jj = 0; jj < w; jj++)
      for (int i = 0; i < h; i++)
        for (int ii = 0; ii < w; ii++)
          for (int k = 0; k < h; k++)
            for (int kk = 0; kk < w; kk++)
              d[k][kk][i][ii] = d[i][ii][k][kk] =
                  min(d[i][ii][k][kk], d[i][ii][j][jj] + d[j][jj][k][kk]);
  int r = 0;
  for (int i = 0; i < h; i++)
    for (int ii = 0; ii < w; ii++)
      for (int k = 0; k < h; k++)
        for (int kk = 0; kk < w; kk++)
          if (d[i][ii][k][kk] < 1e7) r = max(r, d[i][ii][k][kk]);
  cout << r << endl;
  return 0;
}
