#include <bits/stdc++.h>
using namespace std;
const int DIM = 25;
const int inf = 1e9 + 7;
int n, m;
bool v[DIM][DIM];
int dp[DIM][DIM];
bool viz[DIM][DIM];
queue<pair<int, int> > c;
void bfs(int x, int y, int &rez) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) viz[i][j] = false;
  viz[x][y] = true;
  dp[x][y] = 0;
  c.push(make_pair(x, y));
  while (!c.empty()) {
    int x = c.front().first;
    int y = c.front().second;
    c.pop();
    rez = max(rez, dp[x][y]);
    if (v[x + 1][y] == 0 && x + 1 <= n)
      if (viz[x + 1][y] == false) {
        c.push(make_pair(x + 1, y));
        viz[x + 1][y] = true;
        dp[x + 1][y] = dp[x][y] + 1;
      }
    if (v[x][y + 1] == 0 && y + 1 <= m)
      if (viz[x][y + 1] == false) {
        c.push(make_pair(x, y + 1));
        viz[x][y + 1] = true;
        dp[x][y + 1] = dp[x][y] + 1;
      }
    if (v[x][y - 1] == 0 && y - 1 > 0)
      if (viz[x][y - 1] == false) {
        c.push(make_pair(x, y - 1));
        viz[x][y - 1] = true;
        dp[x][y - 1] = dp[x][y] + 1;
      }
    if (v[x - 1][y] == 0 && x - 1 > 0)
      if (viz[x - 1][y] == false) {
        c.push(make_pair(x - 1, y));
        viz[x - 1][y] = true;
        dp[x - 1][y] = dp[x][y] + 1;
      }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char x;
      cin >> x;
      if (x == '.')
        v[i][j] = 0;
      else
        v[i][j] = 1;
    }
  int rez = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      bfs(i, j, rez);
    }
  cout << rez;
  return 0;
}
