#include <bits/stdc++.h>
using namespace std;
int root[200010];
pair<int, pair<int, int> > e[200010];
bool can[200010];
int find_root(int u) {
  if (root[u] == u) return u;
  return root[u] = find_root(root[u]);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) root[i] = i;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    e[i] = pair<int, pair<int, int> >(w, pair<int, int>(u, v));
  }
  sort(e + 1, e + m + 1);
  int ans = 0;
  for (int i = m; i >= 1; i--) {
    int w = e[i].first;
    int u = e[i].second.first, v = e[i].second.second;
    int fu = find_root(u);
    int fv = find_root(v);
    if (fu == fv) {
      if (can[fu] == 0) {
        ans += w;
        can[fu] = 1;
      }
    } else {
      if (can[fu] == 0 || can[fv] == 0) {
        root[fu] = fv;
        if (can[fu]) can[fv] = 1;
        ans += w;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
