#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int n, m, fa[N], b[N], ans;
struct edge {
  int u, v, w;
} e[N];
bool cmp(edge x, edge y) { return x.w > y.w; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n + m; ++i) fa[i] = i;
  for (register int i = 1, x, y, w; i <= m; ++i) {
    scanf("%d%d%d", &x, &y, &w);
    e[i] = (edge){x, y, w};
  }
  sort(e + 1, e + m + 1, cmp);
  for (register int i = 1, x, y; i <= m; ++i) {
    x = find(e[i].u), y = find(e[i].v);
    if (x == y && !b[x]) {
      b[x] = 1;
      ans += e[i].w;
    } else if (x != y && !(b[x] && b[y])) {
      if (b[x] || b[y]) b[y] = 1;
      fa[x] = y;
      ans += e[i].w;
    }
  }
  printf("%d\n", ans);
  return 0;
}
