#include <bits/stdc++.h>
using namespace std;
int const maxn = 2e5 + 5;
int dsu[maxn];
bool vis[maxn];
struct node {
  int a, b;
  long long w;
} p[maxn];
bool cmp(node x, node y) { return x.w > y.w; }
int Find(int x) { return dsu[x] == x ? x : dsu[x] = Find(dsu[x]); }
int main() {
  int n, m, u, v;
  long long res = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) dsu[i] = i;
  for (int i = 0; i < m; i++) scanf("%d%d%lld", &p[i].a, &p[i].b, &p[i].w);
  sort(p, p + m, cmp);
  for (int i = 0; i < m; i++) {
    u = Find(p[i].a);
    v = Find(p[i].b);
    if (u != v) {
      if (vis[u] && vis[v]) continue;
      vis[u] = vis[u] | vis[v];
      res += p[i].w;
      dsu[v] = u;
    } else if (!vis[u]) {
      vis[u] = 1;
      res += p[i].w;
    }
  }
  printf("%lld\n", res);
}
