#include <bits/stdc++.h>
using namespace std;
long long ans = 0, n, m, fa[1000001], d[1000001];
struct Y {
  long long x, y, val;
} a[1000001];
long long find(long long x) {
  if (fa[x] != x) x = fa[x] = find(fa[x]);
  return fa[x];
}
long long cmp(Y x, Y y) { return x.val > y.val; }
signed main() {
  scanf("%lld %lld", &n, &m);
  for (long long i = 1; i <= m; i++)
    scanf("%lld %lld %lld", &a[i].x, &a[i].y, &a[i].val);
  sort(a + 1, a + m + 1, cmp);
  for (long long i = 1; i <= n; i++) fa[i] = i, d[i] = 1;
  for (long long i = 1; i <= m; i++) {
    long long fx = find(a[i].x), fy = find(a[i].y);
    if (fx != fy && d[fx] + d[fy] > 0)
      fa[fx] = fy, d[fy] = d[fx] & d[fy], ans += a[i].val;
    else if (fx == fy && d[fx] == 1)
      d[fx] = 0, ans += a[i].val;
  }
  printf("%lld\n", ans);
}
