#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int fa[200010], vis[200010];
struct point {
  int u, v, w, id;
} a[200010];
bool cmp(point a1, point a2) { return a1.w > a2.w; }
int find(int x) {
  vis[fa[x]] |= vis[x];
  vis[x] |= vis[fa[x]];
  return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i].u, &a[i].v, &a[i].w), a[i].id = i;
    if (a[i].u > a[i].v) swap(a[i].u, a[i].v);
  }
  sort(a + 1, a + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    int x = find(a[i].u), y = find(a[i].v);
    if (x != y && (!vis[x] || !vis[y]))
      fa[x] = y, vis[y] |= vis[x], vis[x] |= vis[y], ans += a[i].w;
    else if (!vis[y])
      vis[y] = true, ans += a[i].w;
  }
  printf("%d\n", ans);
  return 0;
}
