#include <bits/stdc++.h>
const int maxn = 2e5 + 1;
int fa[maxn], flg[maxn], n, m, cnt, ans;
struct Edge {
  int u, v, w;
} e[maxn];
inline bool cmp(Edge a, Edge b) { return a.w > b.w; }
inline int find(int x) { return (fa[x] == x) ? x : fa[x] = find(fa[x]); }
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].w);
  for (int i = 1; i <= n; i++) fa[i] = i;
  std::sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int fx = find(e[i].u), fy = find(e[i].v);
    if (fx == fy) {
      if (flg[fx]) continue;
      ans += e[i].w;
      flg[fx] = 1;
    }
    if (flg[fx] && flg[fy]) continue;
    if (flg[fx])
      fa[fy] = fx;
    else if (flg[fy])
      fa[fx] = fy;
    else
      fa[fx] = fy;
    ans += e[i].w;
  }
  printf("%d", ans);
}
