#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int SUM = 0, ff = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    SUM = (SUM << 3) + (SUM << 1) + (ch ^ 48);
    ch = getchar();
  }
  return SUM * ff;
}
const int N = 200010;
struct edge {
  int u, v, w;
  inline friend bool operator<(edge a1, edge a2) { return a1.w > a2.w; }
} e[N << 2];
int n, m, ans;
int dsu[N], size[N];
inline int find(int x) { return dsu[x] == x ? x : dsu[x] = find(dsu[x]); }
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++)
    e[i].u = read(), e[i].v = read(), e[i].w = read();
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= n; i++) dsu[i] = i, size[i] = 1;
  for (int i = 1; i <= m; i++) {
    int u = find(e[i].u), v = find(e[i].v);
    if (u != v && (size[u] != 0 || size[v] != 0)) {
      dsu[v] = u;
      ans += e[i].w;
      size[u] &= size[v];
    } else if (u == v && size[u]) {
      size[u] = 0;
      ans += e[i].w;
    }
  }
  printf("%d\n", ans);
  return 0;
}
