import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

int[] dx = [1, -1, 0, 0];
int[] dy = [0, 0, 1, -1];

void main() {
    int H, W;
    scan(H, W);

    auto b = new bool[][](H, W);

    foreach (i ; 0 .. H) {
        b[i] = readln.chomp.map!(ch => ch == '.').array;
    }

    auto adj = new int[][](H * W, 0);

    foreach (i ; 0 .. H) {
        foreach (j ; 0 .. W) {
            foreach (k ; 0 .. 4) {
                if (!b[i][j]) continue;
                auto nx = i + dx[k];
                auto ny = j + dy[k];
                if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
                if (!b[nx][ny]) continue;
                adj[W * nx + ny] ~= W * i + j;
                adj[W * i + j] ~= W * nx + ny;
            }
        }
    }

    int ans;

    foreach (i ; 0 .. H) {
        foreach (j ; 0 .. W) {
            ans = max(ans, bfs(adj, W * i + j).filter!(x => x < inf).reduce!max);
        }
    }

    writeln(ans);
}

int[] bfs(int[][] adj, int s) {
    auto N = adj.length.to!int;
    auto dist = new int[](N);

    dist[] = inf;
    dist[s] = 0;

    auto q = Queue!(int)(N);
    q.insert(s);

    while (!q.empty) {
        auto v = q.front;
        q.popFront();

        foreach (u ; adj[v]) {
            if (dist[u] == inf) {
                dist[u] = dist[v] + 1;
                q.insert(u);
            }
        }
    }

    return dist;
}

struct Queue(T) {
    private {
        size_t cap, head, tail;
        T[] data;
    }

    this (size_t n) in {
        assert(n > 0, "The capacity of a queue must be a positive integer.");
    } body {
        cap = n + 1;
        data = new T[](cap);
    }

    void clear() {
        head = tail = 0;
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return head == (tail + 1) % cap;
    }

    size_t length() {
        return head <= tail ? tail - head : cap - head + tail;
    }

    T front() in {
        assert(!empty, "The queue is empty.");
    } body {
        return data[head];
    }

    void removeFront() in {
        assert(!empty, "The queue is empty.");
    } body {
        (++head) %= cap;
    }

    alias popFront = removeFront;

    void insertBack(T x) in {
        assert(!full, "The queue is full.");
    } body {
        data[tail++] = x;
        tail %= cap;
    }

    alias insert = insertBack;

    T[] array() {
        return head <= tail ? data[head .. tail].dup : data[head .. $] ~ data[0 .. tail];
    }

    string toString() {
        import std.format : format;

        if (head <= tail) {
            return format("[%(%s, %)]", data[head .. tail]);
        }
        else {
            return format("[%(%s, %)", data[head .. $]) ~ format(", %(%s, %)]", data[0 .. tail]);
        }
    }
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 1276