#include <bits/stdc++.h>
using namespace std;
struct edge {
  int x, y, w;
  bool operator<(const edge &s) const { return s.w < w; }
} p[200001];
int n, m, f[200001], ans;
bool h[200001];
int rt(int x) { return x == f[x] ? x : (f[x] = rt(f[x])); }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= m; ++i) cin >> p[i].x >> p[i].y >> p[i].w;
  sort(p + 1, p + m + 1);
  for (int i = 1; i <= m; ++i) {
    int x = p[i].x, y = p[i].y;
    x = rt(x), y = rt(y);
    if (x != y) {
      if (!(h[x] && h[y])) {
        ans += p[i].w;
        f[x] = y;
        h[y] = (h[x] || h[y]);
      }
    } else if (!h[x]) {
      ans += p[i].w;
      h[x] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
