#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m;
int f[N], w[N];
long long Min(long long x, long long y) { return x < y ? x : y; }
long long Max(long long x, long long y) { return x > y ? x : y; }
long long R() {
  long long ans = 0, f = 1;
  char c = ' ';
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) ans = ans * 10 + c - '0';
  return ans * f;
}
struct gsqq {
  int a, b, z;
  void In() { a = R(), b = R(), z = R(); }
  bool friend operator<(gsqq a, gsqq b) { return a.z > b.z; }
} q[N];
int Find(int x) { return f[x] == 0 ? x : f[x] = Find(f[x]); }
int main() {
  n = R();
  m = R();
  for (int i = 1; i <= m; ++i) q[i].In();
  sort(q + 1, q + m + 1);
  long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    int f1 = Find(q[i].a), f2 = Find(q[i].b);
    if (f1 == f2) {
      if (w[f1] == 1) continue;
      w[f1] = 1;
      ans += q[i].z;
    } else {
      if (w[f1] + w[f2] >= 2) continue;
      f[f1] = f2;
      w[f2] += w[f1];
      ans += q[i].z;
    }
  }
  printf("%I64d", ans);
  return 0;
}
