#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int f[MAXN], fre[MAXN];
int n, m, res;
pair<int, pair<int, int> > a[MAXN];
int rep(int x) {
  if (f[x] == x) return x;
  return f[x] = rep(f[x]);
}
void join(int a, int b) { f[rep(a)] = rep(b); }
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i].second.first >> a[i].second.second >> a[i].first;
  }
  sort(a, a + m);
  reverse(a, a + m);
  for (int i = 0; i < n; i++) {
    f[i] = i;
    fre[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int ra = rep(a[i].second.first), rb = rep(a[i].second.second);
    if (ra == rb) {
      if (fre[ra] != -1) {
        fre[ra] = -1;
        res += a[i].first;
      }
    } else {
      if (fre[ra] != -1) {
        res += a[i].first;
        f[ra] = rb;
      } else if (fre[rb] != -1) {
        res += a[i].first;
        f[rb] = ra;
      }
    }
  }
  cout << res << endl;
}
