#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 7;
const long long mod = 1e9 + 9;
const long long INF = 1e9 + 7;
const long long mlog = 21;
const long long SQ = 400;
long long f[maxn];
long long mark[maxn], p[maxn], ds[maxn];
long long u[maxn], v[maxn], w[maxn];
bool cmp(long long a, long long b) { return w[a] > w[b]; }
long long get(long long v) { return f[v] = (f[v] == v ? v : get(f[v])); }
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
  ;
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) cin >> v[i] >> u[i] >> w[i];
  iota(p, p + m, 0);
  sort(p, p + m, cmp);
  iota(f, f + n, 0);
  long long ans = 0;
  for (long long j = 0; j < m; j++) {
    long long i = p[j];
    long long x = get(u[i] - 1);
    long long y = get(v[i] - 1);
    if (mark[x] && mark[y]) continue;
    ans += w[i];
    if (mark[x])
      f[y] = x;
    else
      f[x] = y;
    if (x == y) mark[x] = true;
  }
  cout << ans << "\n";
  return 0;
}
