#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> directions = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int bfs(const vector<string> &table, int x, int y) {
  int H = table.size(), W = table[0].size();
  queue<pair<int, int>> que;
  vector<vector<int>> dist(H, vector<int>(W, -1));
  que.push({x, y});
  int ret = 0;
  dist[y][x] = 0;
  while (!que.empty()) {
    int nx = que.front().first, ny = que.front().second;
    que.pop();
    ret = max(ret, dist[ny][nx]);
    for (int i = 0; i < 4; i++) {
      int dx = directions[i].first, dy = directions[i].second;
      if (!(0 <= nx + dx && nx + dx < W && 0 <= ny + dy && ny + dy < H))
        continue;
      else if (table[ny + dy][nx + dx] == '#')
        continue;
      if (dist[ny + dy][nx + dx] == -1) {
        dist[ny + dy][nx + dx] = dist[ny][nx] + 1;
        que.push({nx + dx, ny + dy});
      }
    }
  }
  return ret;
}
int main() {
  int H, W;
  vector<string> table;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    table.push_back(s);
  }
  int ans = 0;
  for (int x = 0; x < W; x++)
    for (int y = 0; y < H; y++) {
      ans = max(bfs(table, x, y), ans);
    }
  cout << ans << endl;
  return 0;
}
