#include <bits/stdc++.h>
using namespace std;
int A[200010], B[200010], C[200010];
int par[200010], sz[200010], ed[200010];
int root(int v) {
  if (par[v] == v) return par[v];
  return par[v] = root(par[v]);
}
int merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y) {
    if (ed[x] < sz[x]) {
      ed[x]++;
      return 1;
    } else
      return 0;
  }
  if (ed[x] + ed[y] + 1 <= sz[x] + sz[y]) {
    par[y] = x;
    sz[x] += sz[y];
    ed[x] += ed[y] + 1;
    return 1;
  }
  return 0;
}
pair<int, pair<int, int> > P[200010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> A[i] >> B[i] >> C[i];
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
  for (int i = 1; i <= m; i++) P[i] = make_pair(C[i], make_pair(A[i], B[i]));
  sort(P + 1, P + m + 1);
  reverse(P + 1, P + m + 1);
  long long int ans = 0LL;
  for (int i = 1; i <= m; i++) {
    A[i] = P[i].second.first;
    B[i] = P[i].second.second;
    C[i] = P[i].first;
  }
  for (int i = 1; i <= m; i++) {
    if (merge(A[i], B[i])) {
      ans += C[i];
    }
  }
  cout << ans << endl;
}
