#include <bits/stdc++.h>
using namespace std;
const int MAXB = 1e7;
char buf[MAXB], *cp = buf;
inline void rd(int &x) {
  x = 0;
  int f = 1;
  while (*cp < '0' || '9' < *cp) {
    if (*cp == '-') f = -1;
    cp++;
  }
  while ('0' <= *cp && *cp <= '9') x = (x << 3) + (x << 1) + *cp - 48, cp++;
  x *= f;
}
const int MAXN = 200010;
int n, m, ans;
int f[MAXN], h[MAXN], full[MAXN];
struct info {
  int a, b, w;
  inline void get() {
    rd(a);
    rd(b);
    rd(w);
  }
} t[MAXN];
bool operator<(info x, info y) { return x.w > y.w; }
void init() {
  for (int i = 1; i <= n; i++) f[i] = i, h[i] = 1, full[i] = 0;
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void uni(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) {
    full[x] = 1;
    return;
  }
  if (h[x] < h[y])
    f[y] = x;
  else if (h[x] > h[y])
    f[x] = y;
  else
    f[x] = y, h[y]++;
}
int main() {
  fread(buf, 1, MAXB, stdin);
  rd(n);
  rd(m);
  for (int i = 0; i < m; i++) t[i].get();
  sort(t, t + m);
  init();
  ans = 0;
  for (int i = 0; i < m; i++) {
    t[i].a = find(t[i].a);
    t[i].b = find(t[i].b);
    if (full[t[i].a] && full[t[i].b]) continue;
    if (full[t[i].a])
      full[t[i].b] = 1;
    else if (full[t[i].b])
      full[t[i].a] = 1;
    else
      uni(t[i].a, t[i].b);
    ans += t[i].w;
  }
  printf("%d\n", ans);
  return 0;
}
