#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, ans = 0;
  cin >> H >> W;
  int dist[H][W], sta[H][W];
  string buf;
  for (int i = 0; i < H; i++) {
    cin >> buf;
    for (int j = 0; j < W; j++) {
      if (buf[j] == '#') {
        sta[i][j] = 0;
        dist[i][j] = 1000;
      } else
        sta[i][j] = 1;
    }
  }
  for (int i = 0; i < (H * W); i++) {
    if (sta[i] == 0) continue;
    for (int j = 0; j < i; j++) {
      if (sta[j] == 0) continue;
      for (int k = 0; k < (H * W); k++) {
        if (sta[k] == 0)
          continue;
        else {
          dist[k / W][k % W] = 500;
          sta[k / W][k % W] = 1;
        }
      }
      dist[i / W][i % W] = 0;
      sta[i / W][i % W] = 2;
      if ((i >= W) && (sta[(i - W) / W][(i - W) % W] == 1))
        dist[(i - W) / W][(i - W) % W] = 1;
      if ((i <= (H * W - W - 1)) && (sta[(i + W) / W][(i + W) % W] == 1))
        dist[(i + W) / W][(i + W) % W] = 1;
      if ((i % W != 0) && (sta[(i - 1) / W][(i - 1) % W] == 1))
        dist[(i - 1) / W][(i - 1) % W] = 1;
      if ((i % W != (W - 1)) && (sta[(i + 1) / W][(i + 1) % W] == 1))
        dist[(i + 1) / W][(i + 1) % W] = 1;
      while (sta[j / W][j % W] == 1) {
        int dec = j;
        for (int k = 0; k < (H * W); k++) {
          if ((sta[k / W][k % W] == 1) &&
              (dist[k / W][k % W] < dist[dec / W][dec % W]))
            dec = k;
        }
        sta[dec / W][dec % W] = 2;
        if ((dec >= W) && (sta[(dec - W) / W][(dec - W) % W] == 1))
          dist[(dec - W) / W][(dec - W) % W] = dist[dec / W][dec % W] + 1;
        if ((dec <= (H * W - W - 1)) &&
            (sta[(dec + W) / W][(dec + W) % W] == 1))
          dist[(dec + W) / W][(dec + W) % W] = dist[dec / W][dec % W] + 1;
        if ((dec % W != 0) && (sta[(dec - 1) / W][(dec - 1) % W] == 1))
          dist[(dec - 1) / W][(dec - 1) % W] = dist[dec / W][dec % W] + 1;
        if ((dec % W != (W - 1)) && (sta[(dec + 1) / W][(dec + 1) % W] == 1))
          dist[(dec + 1) / W][(dec + 1) % W] = dist[dec / W][dec % W] + 1;
      }
      if (dist[j / W][j % W] > ans) ans = dist[j / W][j % W];
    }
  }
  cout << ans << endl;
  return 0;
}
