#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double pie = 3.14159265358979;
const long long mod = 1e9 + 7;
vector<vector<char> > v;
int n, m;
bool vis[25][25];
void read() {
  cin >> n >> m;
  v = vector<vector<char> >(n + 2, vector<char>(m + 2, '#'));
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) cin >> v[i][j];
  }
}
int bfs(int a, int b, int aa, int bb) {
  for (int i = 0; i < n + 2; i++) {
    for (int j = 0; j < m + 2; j++) vis[i][j] = false;
  }
  pair<int, int> src;
  src.first = a, src.second = b;
  pair<int, int> des;
  des.first = aa, des.second = bb;
  queue<pair<int, pair<int, int> > > q;
  q.push({0, src});
  vis[a][b] = 1;
  while (q.empty() == false) {
    auto temp = q.front();
    q.pop();
    int d = temp.first;
    int x = temp.second.first;
    int y = temp.second.second;
    for (int k = 0; k < 4; k++) {
      int to_x = x + dx[k];
      int to_y = y + dy[k];
      if (vis[to_x][to_y] == false && v[to_x][to_y] == '.') {
        pair<int, int> to;
        to.first = to_x;
        to.second = to_y;
        vis[to_x][to_y] = true;
        q.push({d + 1, to});
        if (to_x == aa && to_y == bb) return d + 1;
      }
    }
  }
}
void solve(int test_case) {
  read();
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      for (int ii = 1; ii < n + 1; ii++) {
        for (int jj = 1; jj < m + 1; jj++) ans = max(ans, bfs(i, j, ii, jj));
      }
    }
  }
  cout << ans;
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 0; i < t; i++) solve(i);
  return 0;
}
