#include <bits/stdc++.h>
using namespace std;
const long long N = 200222;
int n, m, a[N], b[N], w[N], par[N], ans, sz[N];
bool mark[N];
pair<int, int> X[N];
int fp(int v) {
  if (par[v] != par[par[v]]) par[v] = fp(par[v]);
  return par[v];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &w[i]);
    X[i].first = w[i], X[i].second = i;
  }
  sort(X + 1, X + m + 1);
  for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
  for (int i = m; i >= 1; i--) {
    int idx = X[i].second, p1 = fp(a[idx]), p2 = fp(b[idx]);
    if (mark[p1] and mark[p2]) continue;
    ans += X[i].first;
    if (p1 == p2)
      mark[p1] = 1;
    else if (mark[p1] or mark[p2])
      mark[p1] = mark[p2] = 1;
    else {
      if (sz[p1] < sz[p2]) swap(p1, p2);
      sz[p1] += sz[p2];
      par[p2] = p1;
    }
  }
  cout << ans;
}
