#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int maze[25][25];
int h, w;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int bfs(pair<int, int> s, pair<int, int> g, vector<string> &table) {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      maze[i][j] = -1;
    }
  }
  maze[s.first][s.second] = 0;
  queue<pair<int, int> > que;
  que.push(s);
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    int x = p.first;
    int y = p.second;
    for (int i = 0; i < 4; ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (table[nx][ny] == '#') continue;
      if (maze[nx][ny] != -1) continue;
      maze[nx][ny] = maze[x][y] + 1;
      que.push(pair<int, int>(nx, ny));
    }
    if (maze[g.first][g.second] != -1) {
      break;
    }
  }
  return maze[g.first][g.second];
}
int main() {
  cin >> h >> w;
  vector<string> table(h);
  for (int i = 0; i < h; ++i) {
    cin >> table[i];
  }
  int res = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      for (int k = 0; k < h; ++k) {
        for (int l = 0; l < w; ++l) {
          res =
              max(res, bfs(pair<int, int>(i, j), pair<int, int>(k, l), table));
        }
      }
    }
  }
  cout << res << endl;
}
