#include <bits/stdc++.h>
using namespace std;
//idk claude code ask claude
vector<int> adj[100005];
bool visited[100005];
int n, m;
pair<int,int> bfs(int start) {
vector<int> dist(n + 1, -1);
queue<int> q;
dist[start] = 0;
q.push(start);
int farthest = start;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v : adj[u]) {
if (dist[v] == -1) {
dist[v] = dist[u] + 1;
if (dist[v] > dist[farthest]) farthest = v;
q.push(v);
}
}
}
return {farthest, dist[farthest]};
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
long long total = 0;
for (int i = 1; i <= n; i++) {
if (!visited[i]) {
// mark component
queue<int> q;
q.push(i);
visited[i] = true;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v : adj[u]) {
if (!visited[v]) {
visited[v] = true;
q.push(v);
}
}
}
// double BFS for diameter
auto [u, _] = bfs(i);
auto [__, d] = bfs(u);
total += d + 1;
}
}
cout << total << "\n";
return 0;
}