#include <bits/stdc++.h>
using namespace std;
struct qwe {
  int x, y, v;
} e[200010];
int n, m, f[200010];
bool ff[200010];
inline int read() {
  int Num = 0, F = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') F = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    Num = (Num << 1) + (Num << 3) + (ch ^ 48);
    ch = getchar();
  }
  return Num * F;
}
inline int getfather(int p) { return f[p] == p ? p : f[p] = getfather(f[p]); }
inline bool my(qwe g, qwe h) { return g.v > h.v; }
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    e[i].x = read();
    e[i].y = read();
    e[i].v = read();
  }
  for (int i = 1; i <= n; i++) f[i] = i;
  sort(e + 1, e + m + 1, my);
  int fx, fy, cnt = 0;
  long long ans = 0;
  for (int i = 1; i <= m; i++) {
    fx = getfather(e[i].x);
    fy = getfather(e[i].y);
    if (fx == fy && ff[fx] || (ff[fx] && ff[fy])) continue;
    f[fx] = fy;
    cnt++;
    ff[fy] = ff[fx] | ff[fy];
    if (fx == fy) ff[fy] = 1;
    ans += (long long)e[i].v;
    if (cnt == n) break;
  }
  printf("%I64d\n", ans);
  return 0;
}
