#include <bits/stdc++.h>
using namespace std;
long long dp[21][21];
long long H, W;
string arr[21];
long long vis[21][21];
long long bfs(long long a, long long b, long long x, long long y) {
  queue<pair<pair<long long, long long>, long long> > q;
  q.push(make_pair(make_pair(a, b), 0));
  for (long long i = 0; i < H; ++i) {
    for (long long j = 0; j < W; ++j) {
      vis[i][j] = false;
      if (arr[i][j] == '#') {
        vis[i][j] = true;
      }
    }
  }
  vis[a][b] = true;
  long long ans = -1;
  while (!q.empty()) {
    pair<pair<long long, long long>, long long> u = q.front();
    q.pop();
    long long i = u.first.first;
    long long j = u.first.second;
    long long d = u.second;
    if (i == x && j == y) {
      ans = d;
      break;
    }
    if (i + 1 < H && vis[i + 1][j] == false) {
      vis[i + 1][j] = true;
      q.push(make_pair(make_pair(i + 1, j), d + 1));
    }
    if (j + 1 < W && vis[i][j + 1] == false) {
      vis[i][j + 1] = true;
      q.push(make_pair(make_pair(i, j + 1), d + 1));
    }
    if (i - 1 >= 0 && vis[i - 1][j] == false) {
      vis[i - 1][j] = true;
      q.push(make_pair(make_pair(i - 1, j), d + 1));
    }
    if (j - 1 >= 0 && vis[i][j - 1] == false) {
      vis[i][j - 1] = true;
      q.push(make_pair(make_pair(i, j - 1), d + 1));
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> H >> W;
  for (long long i = 0; i < H; ++i) {
    string str;
    cin >> str;
    arr[i] = str;
  }
  long long ans = 0;
  for (long long i = 0; i < H; ++i) {
    for (long long j = 0; j < W; ++j) {
      for (long long k = 0; k < H; ++k) {
        for (long long l = 0; l < W; ++l) {
          ans = max(ans, bfs(i, j, k, l));
        }
      }
    }
  }
  cout << ans << endl;
}
