#include <iostream>
#include <vector>
using namespace std;

int depth = 0;
void dfs(int node, vector<vector<int>> &graph, vector<int> & depthOf, int & leaf){
    for(int child : graph[node])
        if(!depthOf[child]){

            depthOf[child] = ++depth;

            if(depthOf[leaf] < depthOf[child])
                leaf = child;

            dfs(child, graph, depthOf, leaf);
            depth--;
        }
}
int main(){

    int nodes, edges, firstLeaf = 0, secondLeaf = 0;
    cin >> nodes >> edges;

    vector<vector<int>> graph(nodes + 1);
    vector<int> depthOf(nodes + 1), beZero(nodes + 1),
                path(nodes + 1);

    while(edges--){
        int from, to;
        cin >> from >> to;

        graph[from].push_back(to);
        graph[to].push_back(from);
    }

    // to get firstLeaf

    int node = 1; // root

    if(!depthOf[node]){

        depthOf[node] = ++depth;

        if(depthOf[firstLeaf] < depthOf[node])
            firstLeaf = node;

        dfs(node, graph, depthOf, firstLeaf);
    }

    // to get SecondLeaf

    node = firstLeaf; // firstLeaf
    depthOf = beZero;
    depth = 0;

    if(!depthOf[node]){

        depthOf[node] = ++depth;
        if(depthOf[secondLeaf] < depthOf[node])
            secondLeaf = node;

        dfs(node, graph, depthOf, secondLeaf);
    }


    cout << endl;
    cout <<"First  Leaf  = "<< firstLeaf << endl;
    cout <<"Second Leaf  = "<< secondLeaf << endl;
    cout <<"Longest Path (edges) = "<< depthOf[secondLeaf] - 1 << endl;
	cout <<"Longest Path (nodes) = "<< depthOf[secondLeaf] << endl;
}
