#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
struct node {
  int x;
  int y;
};
int n, m;
int dst[50][50] = {0};
bool vis[50][50] = {false};
bool vis1[50][50] = {false};
string s[50];
bool check(int x, int y) {
  if (x >= 0 && y >= 0 && x < n && y < m && !vis[x][y] & s[x][y] != '#') {
    return true;
  }
  return false;
}
bool check2(int x, int y) {
  if (x >= 0 && y >= 0 && x < n && y < m && !vis1[x][y] & s[x][y] != '#') {
    return true;
  }
  return false;
}
void bfs(node s) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dst[i][j] = 0;
    }
  }
  queue<node> Q;
  Q.push(s);
  while (!Q.empty()) {
    node u = Q.front();
    Q.pop();
    vis[u.x][u.y] = true;
    for (int i = 0; i < 4; i++) {
      if (check(u.x + dx[i], u.y + dy[i])) {
        Q.push({u.x + dx[i], u.y + dy[i]});
        dst[u.x + dx[i]][u.y + dy[i]] = dst[u.x][u.y] + 1;
      }
    }
  }
}
void bfs2(node s) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dst[i][j] = 0;
    }
  }
  queue<node> Q;
  Q.push(s);
  while (!Q.empty()) {
    node u = Q.front();
    Q.pop();
    vis1[u.x][u.y] = true;
    for (int i = 0; i < 4; i++) {
      if (check2(u.x + dx[i], u.y + dy[i])) {
        Q.push({u.x + dx[i], u.y + dy[i]});
        dst[u.x + dx[i]][u.y + dy[i]] = dst[u.x][u.y] + 1;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  node t;
  int ans = -1;
  int correct_ans = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] != '#' && !vis[i][j]) {
        bfs({i, j});
        ans = -1;
        for (int i = 0; i < n; i++) {
          for (int j = 0; j < m; j++) {
            if (dst[i][j] > ans) {
              ans = dst[i][j];
              t = {i, j};
            }
          }
        }
        bfs2(t);
        for (int i = 0; i < n; i++) {
          for (int j = 0; j < m; j++) {
            correct_ans = max(correct_ans, dst[i][j]);
          }
        }
      }
    }
  }
  cout << correct_ans << endl;
  return 0;
}
