#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int n, m, a[N], b[N], w[N], id[N];
inline bool cmp(int A, int B) { return w[A] > w[B]; }
int fa[N];
long long val[N];
bool vis[N];
int Fnd(int u) { return fa[u] == u ? u : fa[u] = Fnd(fa[u]); }
inline bool Mrg(int u, int v) {
  int Fu = Fnd(u), Fv = Fnd(v);
  if (Fu == Fv) {
    if (!vis[Fu])
      vis[Fu] = 1;
    else if (vis[Fv])
      return 0;
    return 1;
  }
  int k1 = vis[Fu], k2 = vis[Fv];
  fa[Fv] = Fu;
  if (k1 && k2) return 0;
  if (k1 || k2) vis[Fu] = 1;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = (1); i <= (m); ++i)
    scanf("%d%d%d", a + i, b + i, w + i), id[i] = i;
  sort(id + 1, id + m + 1, cmp);
  for (register int i = (1); i <= (n); ++i) fa[i] = i, vis[i] = 0;
  long long Ans = 0;
  for (register int i = (1); i <= (m); ++i) {
    if (Mrg(a[id[i]], b[id[i]])) Ans += w[id[i]];
  }
  printf("%lld\n", Ans);
  return 0;
}
