#include <bits/stdc++.h>
using namespace std;
long long fa[200010], c[200010], n, m, ans;
struct Node {
  int x, y, z;
} a[200010];
bool cmp1(const Node &s1, const Node &s2) { return s1.z > s2.z; }
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline int get(int x) {
  if (fa[x] == x) return x;
  return fa[x] = get(fa[x]);
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) fa[i] = i, c[i] = 0;
  for (int i = 1; i <= m; i++) {
    a[i].x = read(), a[i].y = read(), a[i].z = read();
  }
  sort(a + 1, a + 1 + m, cmp1);
  for (int i = 1; i <= m; i++) {
    int fx = get(a[i].x), fy = get(a[i].y);
    if (c[fx] && c[fy]) continue;
    if (fx == fy) {
      ans += a[i].z;
      c[fy] = 1;
    } else {
      ans += a[i].z;
      fa[fx] = fy;
      c[fy] |= c[fx];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
