#include <bits/stdc++.h>
using namespace std;
struct data {
  int u, v, w;
} p[400500];
int father[200100];
int use[200100];
int coo(struct data a, struct data b) {
  if (a.w > b.w) return 1;
  return 0;
}
int find(int x) { return x == father[x] ? x : father[x] = find(father[x]); }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) father[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &p[i].u, &p[i].v, &p[i].w);
  }
  sort(p + 1, p + m + 1, coo);
  long long ans = 0;
  for (int i = 1; i <= m; i++) {
    int x = find(p[i].u), y = find(p[i].v);
    if (use[x] && use[y]) continue;
    if (x == y)
      use[x] = 1;
    else {
      father[x] = y;
      use[y] |= use[x];
    }
    ans += p[i].w;
  }
  cout << ans << endl;
  return 0;
}
