#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int H, W, maxx = -1;
char G[20][20];
int vis[20][20];
int level[20][20];
vector<int> graph[20];
void bfs(int i, int j) {
  vis[i][j] = true;
  level[i][j] = 1;
  queue<pair<int, int>> q;
  pair<int, int> p;
  q.push(make_pair(i, j));
  while (!q.empty()) {
    pair<int, int> r = q.front();
    vis[r.first][r.second] = 1;
    q.pop();
    for (int k = 0; k < 4; k++) {
      int di = i + dx[k], dj = j + dy[k];
      if (vis[di][dj] || di < 0 || dj < 0 || di >= H || dj >= W)
        continue;
      else {
        level[di][dj] = level[r.first][r.second] + 1;
        maxx = max(maxx, level[di][dj]);
        q.push(make_pair(di, dj));
      }
    }
  }
}
int main() {
  cin >> H >> W;
  char G[H][W];
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) G[i][j] = s[j];
  }
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      memset(vis, 0, sizeof vis);
      bfs(i, j);
    }
  cout << maxx - 1;
}
