#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int A[MAXN], B[MAXN], W[MAXN];
int uni[MAXN];
bool tr[MAXN];
int s[MAXN];
int guni(int x) { return x == uni[x] ? x : uni[x] = guni(uni[x]); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) cin >> A[i] >> B[i] >> W[i];
  for (int i = 1; i <= N; i++) {
    uni[i] = i;
    tr[i] = true;
  }
  for (int i = 0; i < M; i++) s[i] = i;
  sort(s, s + M, [&](const int a, const int b) { return W[a] > W[b]; });
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int a = guni(A[s[i]]);
    int b = guni(B[s[i]]);
    if (a == b && tr[a]) {
      ans += W[s[i]];
      tr[a] = false;
    } else if (a != b && (tr[a] || tr[b])) {
      ans += W[s[i]];
      uni[a] = b;
      tr[b] &= tr[a];
    }
  }
  cout << ans;
  return 0;
}
