#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

ll n, m;

pair<ll, ll> bfs(ll start, const vector<vector<ll>> &adj) {
    vector<ll> dist(n + 1, -1);
    queue<ll> q;
    q.push(start);
    dist[start] = 0;
    ll far = start;

    while (!q.empty()) {
        ll u = q.front(); q.pop();
        for (auto &v : adj[u]) {
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
                if (dist[v] > dist[far]) {
                    far = v;
                }
            }
        }
    }
    return {far, dist[far]};
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    vector<vector<ll>> adj(n + 1, vector<ll>());

    for (ll i = 0; i < m; i++) {
        ll u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<bool> vis(n +1, false);

    ll sum_d = 0;
    ll k = 0;
    
    for(ll u =1; u <=n; u++) {
        if(!vis[u]){
            k++;
            auto [ff, fd1] = bfs(u, adj);
            auto [sf, sd] = bfs(ff, adj);
            sum_d += sd;

            queue<ll> qvis;
            qvis.push(u);
            vis[u] = true;
            while(!qvis.empty()){
                ll node = qvis.front(); qvis.pop();
                for(auto &v : adj[node]){
                    if(!vis[v]){
                        vis[v] = true;
                        qvis.push(v);
                    }
                }
            }
        }
    }

    if(k == 1){
        cout << sum_d + 1 << '\n';
    }
    else{
        cout << sum_d + k << '\n';
    }
}