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


ll n, m;
vector<vector<ll>> adj;
vector<char> vis_marker; 


pair<ll, ll> bfs(ll start){
    deque<ll> q;
    q.push_back(start);
    ll farthest_node = start;
    ll max_distance = 0;
    vector<ll> dist(n + 1, -1);
    dist[start] = 0;
    vis_marker[start] = 1;

    while(!q.empty()){
        ll u = q.front();
        q.pop_front();
        for(auto &v : adj[u]){
            if(!vis_marker[v]){
                vis_marker[v] = 1;
                dist[v] = dist[u] + 1;
                q.push_back(v);
                if(dist[v] > max_distance){
                    max_distance = dist[v];
                    farthest_node = v;
                }
            }
        }
    }
    return {farthest_node, max_distance};
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    adj.assign(n + 1, vector<ll>());
    ll u, v;

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

    
    vis_marker.assign(n + 1, 0);

    ll sum_d = 0;
    ll k = 0;

    for(ll u = 1; u <= n; ++u){
        if(!vis_marker[u]){
            k++;
            
            pair<ll, ll> first_bfs = bfs(u);
            ll ff = first_bfs.first;

            
            pair<ll, ll> second_bfs = bfs(ff);
            ll sd = second_bfs.second;

            sum_d += sd;
        }
    }

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