#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >>n>>m;
    vector<vector<int>> graph(n);
    for (int i=0; i<m; i++) {
        int a,b;
        cin >>a >>b;
        graph[a-1].push_back(b-1);
        graph[b-1].push_back(a-1);
    }
    set<int> visited;
    map<int, vector<int>> components;
    int current_component = 0;
    for (int vertice=0; vertice<n; vertice++) {
        if (visited.count(vertice)==0) {
            visited.insert(vertice);
            queue<int> queue;
            queue.push(vertice);
            while (!queue.empty()) {
                int v = queue.front();
                queue.pop();
                components[current_component].push_back(v);
                for (int neighbour : graph[v]) {
                    if (visited.count(neighbour)==0) {
                        visited.insert(neighbour);
                        queue.push(neighbour);
                    }
                }
            }
        }
        current_component++;
    }
    long r = 0;
    for (auto c : components)
         for (int v : c.second)
             r += c.second.size() - graph[v].size() - 1;
    cout <<r/2<<endl;
}
