#include <bits/stdc++.h>
using namespace std;
priority_queue<tuple<long long int, long long int, long long int> > pq;
long long int p[200005];
bool done[200005];
long long int findset(long long int x) {
  return x == p[x] ? x : p[x] = findset(p[x]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int n, m, i, j, k, a, b, c, ans = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++) p[i] = i;
  for (i = 0; i < m; i++) {
    cin >> a >> b >> c;
    pq.push(make_tuple(c, a, b));
  }
  while (pq.size()) {
    tie(c, a, b) = pq.top();
    pq.pop();
    a = findset(a);
    b = findset(b);
    if (a == b) {
      if (done[a]) continue;
      done[a] = true;
      ans += c;
      continue;
    }
    if (done[a] && done[b]) continue;
    p[a] = b;
    if (done[a]) done[b] = true;
    ans += c;
  }
  cout << ans;
}
