#include <bits/stdc++.h>
using namespace std;
struct mess {
  int p1, p2, u;
  mess(int x, int y, int z) : p1(x), p2(y), u(z) {}
  mess() {}
  bool operator<(const mess &x) const { return u > x.u; }
};
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
mess info[200000 + 10];
int fa[200000 + 10];
bool used[200000 + 10];
int n, m;
int find(int x) { return fa[x] == x ? fa[x] : (fa[x] = find(fa[x])); }
bool merge(int x, int y) {
  int f1 = find(x), f2 = find(y);
  if (f1 != f2 && (used[f1] || used[f2])) {
    fa[f2] = f1;
    used[f1] = used[f1] & used[f2];
    return true;
  }
  if (f1 == f2 && used[f1]) {
    used[f1] = 0;
    return true;
  }
  return false;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) fa[i] = i, used[i] = 1;
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), z = read();
    info[i] = mess(x, y, z);
  }
  sort(info + 1, info + m + 1);
  long long ans = 0;
  for (int i = 1; i <= m; i++)
    if (merge(info[i].p1, info[i].p2)) ans += 1ll * info[i].u;
  printf("%lld\n", ans);
  return 0;
}
