#include <bits/stdc++.h>
using namespace std;
const int MAXW = 20;
const int MAXH = 20;
const int INF = 40000;
int h, w;
char maze[MAXW][MAXH];
bool visited[MAXW][MAXH];
int dist[MAXW][MAXH];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
void fill() {
  for (int x = 0; x < w; x++) {
    for (int y = 0; y < h; y++) {
      if (maze[x][y] == '.') {
        dist[x][y] = INF;
      } else {
        dist[x][y] = 0;
      }
    }
  }
}
int bfs(int x, int y) {
  fill();
  dist[x][y] = 0;
  queue<pair<int, int> > que;
  que.push(pair<int, int>(x, y));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    visited[p.first][p.second] = true;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] == '.' &&
          !visited[nx][ny]) {
        dist[nx][ny] = dist[p.first][p.second] + 1;
        que.push(pair<int, int>(nx, ny));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  return ans;
}
void solve() {
  int ans = 0;
  for (int x = 0; x < w; x++) {
    for (int y = 0; y < h; y++) {
      if (maze[x][y] == '.') {
        memset(visited, 0, sizeof(visited));
        ans = max(ans, bfs(x, y));
      }
    }
  }
  cout << ans << endl;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> maze[j][i];
    }
  }
  solve();
}
