#include <bits/stdc++.h>
using namespace std;
const int _ = 2e5 + 5;
inline int read() {
  char ch = '!';
  int z = 1, num = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') z = -1, ch = getchar();
  while (ch <= '9' && ch >= '0')
    num = (num << 3) + (num << 1) + ch - '0', ch = getchar();
  return z * num;
}
int n, m, fa[_], V[_];
struct ha {
  int a, b, w;
  bool operator<(const ha &A) const { return w > A.w; }
} t[_];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i) fa[i] = i, V[i] = 0;
  for (int i = 1; i <= m; ++i)
    t[i].a = read(), t[i].b = read(), t[i].w = read();
  sort(t + 1, t + 1 + m);
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    int u = find(t[i].a), v = find(t[i].b);
    if (V[u] && V[v]) continue;
    if (u != v) {
      fa[v] = u;
      ans += t[i].w;
      V[u] |= V[v];
    } else {
      int k = V[u] ? v : u;
      V[k] |= 1;
      ans += t[i].w;
    }
  }
  printf("%d\n", ans);
  return 0;
}
