#include <bits/stdc++.h>
using namespace std;
int n, m, fa[1000000], flag, ans;
bool tag[1000000];
int read() {
  int x = 0, k = 1;
  char c;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * k;
}
struct node {
  int u, v, w;
  node(int a = 0, int b = 0, int c = 0) { u = a, v = b, w = c; }
  friend bool operator<(const node& a, const node& b) { return a.w > b.w; }
} e[1000000];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), w = read();
    e[i] = node(x, y, w);
  }
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= m; i++) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    int fu = find(u), fv = find(v);
    if (fu != fv && (!tag[fu] || !tag[fv]))
      fa[fu] = fv, tag[fv] |= tag[fu], ans += w;
    else if (fu == fv) {
      if (!tag[fu]) tag[fu] = 1, ans += w;
    }
  }
  printf("%d\n", ans);
  return 0;
}
