#include <bits/stdc++.h>
using namespace std;
const int _ = 1e2;
const int maxn = 2e5 + _;
int fa[maxn], c[maxn];
int findfa(int x) {
  if (abs(fa[x]) == x) return x;
  fa[x] = findfa(fa[x]);
  return fa[x];
}
struct edge {
  int x, y, w;
} e[maxn];
bool cmp(edge e1, edge e2) { return e1.w > e2.w; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].w);
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= n; i++) fa[i] = i;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int fx = findfa(e[i].x), fy = findfa(e[i].y);
    if (fx != fy) {
      if (!c[fx] || !c[fy]) {
        c[fy] += c[fx];
        fa[fx] = fy;
        ans += e[i].w;
      }
    } else {
      if (!c[fx]) {
        c[fx]++;
        ans += e[i].w;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
