#include <bits/stdc++.h>
using namespace std;
long long sum(long long l, long long r) { return (l + r) * (r - l + 1) / 2; }
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
long long arr[100001];
long long f[100001];
long long ma[100001];
long long ans[100001];
long long Find(long long x) {
  if (x == f[x]) return x;
  return f[x] = Find(f[x]);
}
const long long Mod = 1e9 + 7;
long long fastPower(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power & 1) {
      result = result * base % Mod;
    }
    power >>= 1;
    base = (base * base) % Mod;
  }
  return result;
}
long long Inv(long long x) { return fastPower(x, Mod - 2); }
long long nChoosek(long long n, long long k) {
  long long ans = 1;
  for (long long i = 1; i <= k; ++i)
    ans = ans * Inv(i) % Mod * (n - i + 1) % Mod;
  return ans % Mod;
}
char maze[21][21];
long long visit[22][22];
struct Point {
  long long x;
  long long y;
  long long d;
};
long long H, W;
long long depth = 0;
void bfs(long long x, long long y) {
  queue<Point> q;
  Point p;
  p.x = x;
  p.y = y;
  p.d = 0;
  q.push(p);
  while (!q.empty()) {
    Point tmp = q.front();
    q.pop();
    long long x1 = tmp.x;
    long long y1 = tmp.y;
    long long d1 = tmp.d;
    visit[x1][y1] = 1;
    depth = max(depth, d1);
    if (x1 + 1 < H) {
      if (maze[x1 + 1][y1] == '.' && visit[x1 + 1][y1] == 0) {
        Point p2;
        p2.x = x1 + 1;
        p2.y = y1;
        p2.d = d1 + 1;
        q.push(p2);
      }
    }
    if (y1 + 1 < W) {
      if (maze[x1][y1 + 1] == '.' && visit[x1][y1 + 1] == 0) {
        Point p2;
        p2.x = x1;
        p2.y = y1 + 1;
        p2.d = d1 + 1;
        q.push(p2);
      }
    }
    if (x1 - 1 >= 0) {
      if (maze[x1 - 1][y1] == '.' && visit[x1 - 1][y1] == 0) {
        Point p2;
        p2.x = x1 - 1;
        p2.y = y1;
        p2.d = d1 + 1;
        q.push(p2);
      }
    }
    if (y1 - 1 >= 0) {
      if (maze[x1][y1 - 1] == '.' && visit[x1][y1 - 1] == 0) {
        Point p2;
        p2.x = x1;
        p2.y = y1 - 1;
        p2.d = d1 + 1;
        q.push(p2);
      }
    }
  }
}
map<long long, long long> m;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> H >> W;
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      cin >> maze[i][j];
    }
  }
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      if (maze[i][j] == '.') {
        memset(visit, 0, sizeof(visit));
        bfs(i, j);
      }
    }
  }
  cout << depth << "\n";
}
