#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, v;
} a[1011000];
bool cmp(node x, node y) { return x.v > y.v; }
int n, m, i, ans, fa[1011000], vis[1011000], f1, f2;
int find(int x) {
  if (fa[x] == x) return x;
  fa[x] = find(fa[x]);
  return fa[x];
}
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].v);
  }
  sort(a + 1, a + 1 + m, cmp);
  for (i = 1; i <= n; i++) fa[i] = i;
  for (i = 1; i <= m; i++) {
    f1 = find(a[i].x), f2 = find(a[i].y);
    if (f1 != f2) {
      if (vis[f1] == 1 && vis[f2] == 1) continue;
      if (vis[f1] == 1) swap(f1, f2);
      fa[f1] = f2;
      ans += a[i].v;
      continue;
    }
    if (vis[f1] == 0) vis[f1] = 1, ans += a[i].v;
  }
  printf("%d\n", ans);
}
