#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")
template <typename T>
void print(T&& x) {
  cout << x << "\n";
}
template <typename T, typename... S>
void print(T&& x, S&&... y) {
  cout << x << ' ';
  print(y...);
}
const long long Mod = 1000000007, Mod2 = 998244353;
const long long MOD = Mod;
const long long maxn = 200005;
long long n, m, par[maxn];
bool a[maxn];
struct edge {
  long long u, v, w;
  bool operator<(const edge& o) const { return w > o.w; }
} e[maxn];
long long Find(long long x) { return x == par[x] ? x : par[x] = Find(par[x]); }
bool Union(long long x, long long y) {
  x = Find(x), y = Find(y);
  if (x == y) {
    if (a[x]) return 0;
    a[x] = 1;
    return 1;
  }
  if (a[x] && a[y]) return 0;
  par[y] = x;
  a[x] |= a[y];
  return 1;
}
void orzck() {
  cin >> n >> m;
  for (long long i = (0); i < ((long long)(n)); i++) par[i] = i;
  for (long long i = (0); i < ((long long)(m)); i++) {
    cin >> e[i].u >> e[i].v >> e[i].w;
    e[i].u--, e[i].v--;
  }
  sort(e, e + m);
  long long ans = 0;
  for (long long i = (0); i < ((long long)(m)); i++) {
    if (Union(e[i].u, e[i].v)) ans += e[i].w;
  }
  print(ans);
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long t;
  t = 1;
  while (t--) orzck();
  return 0;
}
