#include <bits/stdc++.h>
using namespace std;
struct uftree {
  int par[200005];
  int rank[200005];
  int flag[200005];
  uftree() {}
  void init(int n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
      flag[i] = 0;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
      if (flag[x] == 1) flag[y] = 1;
    } else {
      if (rank[x] == rank[y]) rank[x]++;
      par[y] = x;
      if (flag[y] == 1) flag[x] = 1;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
uftree uf;
int n, m;
pair<int, pair<int, int> > vec[200005];
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &vec[i].second.first, &vec[i].second.second, &vec[i].first);
  }
  sort(vec, vec + m);
  reverse(vec, vec + m);
  long long ans = 0;
  uf.init(n);
  for (int i = 0; i < m; i++) {
    int x = uf.find(vec[i].second.first);
    int y = uf.find(vec[i].second.second);
    if (x != y) {
      if (uf.flag[x] == 1 && uf.flag[y] == 1) continue;
      ans += vec[i].first;
      uf.unite(vec[i].second.first, vec[i].second.second);
    } else {
      if (uf.flag[x] == 0) {
        uf.flag[x] = 1;
        ans += vec[i].first;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
