#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  bool mo[401] = {false};
  bool m[401] = {false};
  int cost[401];
  for (int j = 0; j < (int)(H); j++) {
    for (int i = 0; i < (int)(W); i++) {
      char c;
      cin >> c;
      if (c == '.') {
        mo[j * W + i] = true;
      } else {
        mo[j * W + i] = false;
      }
    }
  }
  int imax = 0;
  for (int k = 0; k < (int)(H * W); k++) {
    for (int i = 0; i < (int)(W * H); i++) {
      cost[i] = 10000;
      m[i] = mo[i];
    }
    cost[k] = 0;
    m[k] = false;
    for (int i = 0; i < (int)(H * W); i++) {
      for (int j = 0; j < (int)(H * W); j++) {
        if (cost[j] == i) {
          imax = max(imax, i);
          if (j % W != 0) {
            if (m[j - 1] == true) {
              m[j - 1] = false;
              cost[j - 1] = i + 1;
            }
          }
          if (j % W != W - 1) {
            if (m[j + 1] == true) {
              m[j + 1] = false;
              cost[j + 1] = i + 1;
            }
          }
          if (j >= W) {
            if (m[j - W] == true) {
              m[j - W] = false;
              cost[j - W] = i + 1;
            }
          }
          if (j + W < H * W) {
            if (m[j + W] == true) {
              m[j + W] = false;
              cost[j + W] = i + 1;
            }
          }
        }
      }
    }
  }
  cout << imax << endl;
}
