#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long n, m, ans, fa[200005], flag[200005];
struct edge {
  long long u, v, w;
} e[200005];
bool cmp(edge x, edge y) { return x.w > y.w; }
long long find(long long x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  n = read();
  m = read();
  for (long long i = 1; i <= m; ++i) {
    long long u = read(), v = read(), w = read();
    e[i] = (edge){u, v, w};
  }
  sort(e + 1, e + 1 + m, cmp);
  for (long long i = 1; i <= n; ++i) fa[i] = i;
  for (long long i = 1; i <= m; ++i) {
    long long p = find(e[i].u), q = find(e[i].v);
    if (p != q) {
      if (flag[p] && flag[q]) continue;
      flag[p] |= flag[q];
      fa[q] = p;
      ans += e[i].w;
    } else if (!flag[p]) {
      flag[p] = 1;
      ans += e[i].w;
    }
  }
  printf("%lld", ans);
}
