#include <bits/stdc++.h>
int dx4[] = {1, 0, -1, 0};
int dy4[] = {0, -1, 0, 1};
long long int gcd(long long int x, long long int y) {
  if (!y) return x;
  return gcd(y, x % y);
}
long long int lcm(long long int x, long long int y) {
  return x / gcd(x, y) * y;
}
void swap(long long int* x, long long int* y) {
  long long int tmp = *x;
  *x = *y;
  *y = tmp;
}
int asc_cmp(const void* X, const void* Y) {
  long long int x = *(int*)X, y = *(int*)Y;
  if (x < y)
    return -1;
  else if (x == y)
    return 0;
  else
    return 1;
}
int desc_cmp(const void* X, const void* Y) {
  long long int x = *(int*)X, y = *(int*)Y;
  if (x < y)
    return 1;
  else if (x == y)
    return 0;
  else
    return -1;
}
typedef struct data_ {
  int x;
  int y;
} data_t;
typedef struct queue_ {
  int n, f, t;
  data_t data[100000];
  int (*size)();
  int (*front)();
  int (*tail)();
  void (*enqueue)(data_t);
  data_t (*dequeue)();
  void (*init)();
  int (*isEmpty)();
} queue_t;
queue_t queue;
int size() { return queue.n; }
int front() { return queue.f; }
int tail() { return queue.t; }
void enqueue(data_t data) {
  queue.n++;
  queue.data[queue.t++] = data;
}
data_t dequeue() {
  queue.n--;
  return queue.data[queue.f++];
}
void init() { queue.f = queue.t = queue.n = 0; }
int isEmpty() { return queue.n ? 0 : 1; }
void setQueue() {
  queue.size = size;
  queue.front = front;
  queue.tail = tail;
  queue.enqueue = enqueue;
  queue.dequeue = dequeue;
  queue.init = init;
  queue.isEmpty = isEmpty;
}
int h, w;
char s[40][40];
int dist[40][40];
int bfs(int x, int y) {
  if (s[y][x] == '#') return -1;
  int max = -1;
  dist[y][x] = 0;
  data_t data, now;
  data.x = x;
  data.y = y;
  queue.enqueue(data);
  while (!queue.isEmpty()) {
    now = queue.dequeue();
    for (int i = 0; i < 4; i++) {
      data.x = now.x + dx4[i];
      data.y = now.y + dy4[i];
      if (s[data.y][data.x] == '.' && dist[data.y][data.x] == -1 &&
          (0 <= data.x && data.x < w) && (0 <= data.y && data.y < h)) {
        queue.enqueue(data);
        dist[data.y][data.x] = dist[now.y][now.x] + 1;
        max = ((max) > (dist[data.y][data.x]) ? (max) : (dist[data.y][data.x]));
      }
    }
  }
  return max;
}
void initdist() {
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      dist[i][j] = -1;
    }
  }
}
int main() {
  setQueue();
  queue.init();
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
  }
  int ans = -1, x;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      initdist();
      x = bfs(j, i);
      ans = ((x) > (ans) ? (x) : (ans));
    }
  }
  printf("%d\n", ans);
}
