#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> >graph;
vector<bool> visited;
int max_distance, x;
void DFS ( int node, int parent, int distance ){
if ( distance > max_distance ){
max_distance = distance;
x = node;
}
for ( auto neighbour : graph[node] ){
if ( neighbour != parent )
DFS(neighbour, node, distance + 1);
}
}
int main()
{
int n, m;
cin >> n >> m;
graph.resize(n);
for ( int i = 0; i < m; i++ ){
int u, v;
cin >> u >> v;
graph[u].emplace_back(v);
graph[v].emplace_back(u);
}
max_distance = -1;
DFS(0, -1, 0);
int y = x;
max_distance = -1;
DFS(y, -1, 0);
int z = x;
int diameter = max_distance;
cout << diameter << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPHZlY3RvcjxpbnQ+ID5ncmFwaDsKdmVjdG9yPGJvb2w+IHZpc2l0ZWQ7CgppbnQgbWF4X2Rpc3RhbmNlLCB4Owp2b2lkIERGUyAoIGludCBub2RlLCBpbnQgcGFyZW50LCBpbnQgZGlzdGFuY2UgKXsKICAgIAogICAgaWYgKCBkaXN0YW5jZSA+IG1heF9kaXN0YW5jZSApewogICAgICAgIG1heF9kaXN0YW5jZSA9IGRpc3RhbmNlOwogICAgICAgIHggPSBub2RlOwogICAgfQogICAgCiAgICBmb3IgKCBhdXRvIG5laWdoYm91ciA6IGdyYXBoW25vZGVdICl7CiAgICAgICAgaWYgKCBuZWlnaGJvdXIgIT0gcGFyZW50ICkKICAgICAgICAgICAgREZTKG5laWdoYm91ciwgbm9kZSwgZGlzdGFuY2UgKyAxKTsKICAgIH0KfQoKaW50IG1haW4oKQp7CiAgICBpbnQgbiwgbTsKICAgIGNpbiA+PiBuID4+IG07CiAgICBncmFwaC5yZXNpemUobik7CiAgICAKICAgIGZvciAoIGludCBpID0gMDsgaSA8IG07IGkrKyApewogICAgICAgIGludCB1LCB2OwogICAgICAgIGNpbiA+PiB1ID4+IHY7CiA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