#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
int R, C;
int H, W;
int sy, sx;
int gy, gx;
string c[51];
int d[51][51];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve() {
  queue<pair<int, int> > qp;
  qp.push({sy, sx});
  for (int i = 0; i < 51; i++) {
    for (int j = 0; j < 51; j++) {
      d[i][j] = 10000;
    }
  }
  d[sy][sx] = 0;
  while (!qp.empty()) {
    pair<int, int> p = qp.front();
    qp.pop();
    int y = p.first, x = p.second;
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny >= 0 && ny < H && nx >= 0 && nx < W) {
        if (c[ny][nx] != '#' && d[ny][nx] > d[y][x] + 1) {
          d[ny][nx] = d[y][x] + 1;
          qp.push({ny, nx});
        }
      }
    }
  }
}
void resett() {
  for (int i = 0; i < 51; i++) {
    for (int j = 0; j < 51; j++) {
      d[i][j] = 0;
    }
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> c[i];
  }
  int max = 0;
  for (int i = 0; i < H; i++) {
    sy = i;
    for (int j = 0; j < W; j++) {
      sx = j;
      for (int k = 0; k < H; k++) {
        gy = k;
        for (int l = 0; l < W; l++) {
          gx = l;
        }
        if (c[sy][sx] == '#' || c[gy][gx] == '#') {
          continue;
        }
        solve();
        if (d[gy][gx] > max) max = d[gy][gx];
      }
    }
  }
  cout << max << endl;
}
