#include <bits/stdc++.h>
using namespace std;
char s[20][20];
int h, w;
class pos {
 public:
  int h;
  int w;
  int step;
  pos(int i, int j, int s);

 private:
};
pos::pos(int i, int j, int s) {
  h = i;
  w = j;
  step = s;
}
int cost(pos src) {
  int c[20][20];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      c[i][j] = 100000;
    }
  }
  vector<pos> index{src};
  int itr = 0;
  while (itr < index.size()) {
    int i = index[itr].h;
    int j = index[itr].w;
    if (i != h - 1) {
      if (c[i + 1][j] > index[itr].step + 1 && s[i + 1][j] == '.') {
        c[i + 1][j] = index[itr].step + 1;
        pos tmp(i + 1, j, index[itr].step + 1);
        index.push_back(tmp);
      }
    }
    if (j != w - 1) {
      if (c[i][j + 1] > index[itr].step + 1 && s[i][j + 1] == '.') {
        c[i][j + 1] = index[itr].step + 1;
        pos tmp(i, j + 1, index[itr].step + 1);
        index.push_back(tmp);
      }
    }
    if (i != 0) {
      if (c[i - 1][j] > index[itr].step + 1 && s[i - 1][j] == '.') {
        c[i - 1][j] = index[itr].step + 1;
        pos tmp(i - 1, j, index[itr].step + 1);
        index.push_back(tmp);
      }
    }
    if (j != 0) {
      if (c[i][j - 1] > index[itr].step + 1 && s[i][j - 1] == '.') {
        c[i][j - 1] = index[itr].step + 1;
        pos tmp(i, j - 1, index[itr].step + 1);
        index.push_back(tmp);
      }
    }
    itr++;
  }
  int max = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (c[i][j] > max && c[i][j] != 100000) {
        max = c[i][j];
      }
    }
  }
  return max;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string tmp;
    cin >> tmp;
    for (int j = 0; j < w; j++) {
      s[i][j] = tmp[j];
    }
  }
  int max = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      pos src(i, j, 0);
      int tmp = cost(src);
      if (tmp > max) {
        max = tmp;
      }
    }
  }
  cout << max << endl;
}
