#include <bits/stdc++.h>
using namespace std;
using tint = tuple<int, int, int>;
const int maxn = 200004;
int N, M;
tint a[maxn];
struct dsu {
  dsu() { iota(p, p + maxn, 0); }
  int p[maxn], add[maxn];
  int root(int k) { return p[k] != k ? p[k] = root(p[k]) : k; }
  bool connect(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    p[y] = x;
    add[x] |= add[y];
    return true;
  }
} d;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    a[i] = tint(x, y, w);
  }
  sort(a, a + M, [](tint x, tint y) { return get<2>(x) > get<2>(y); });
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int x, y, w;
    tie(x, y, w) = a[i];
    if (d.root(x) != d.root(y) and not(d.add[d.root(x)] and d.add[d.root(y)])) {
      ans += w;
      d.connect(x, y);
    } else if (!d.add[d.root(x)]) {
      ans += w;
      d.add[d.root(x)] = true;
    }
  }
  cout << ans << '\n';
}
