#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, N = 2e5 + 5;
int par[N], over[N];
int getpar(int u) {
  if (par[par[u]] == par[u]) return par[u];
  return par[u] = getpar(par[u]);
}
bool unite(int a, int b) {
  a = getpar(a);
  b = getpar(b);
  if (a == b) {
    if (over[a]) return false;
    over[a] += 1;
    return true;
  } else {
    if (over[a] && over[b]) {
      return false;
    }
    par[a] = b;
    over[b] += over[a];
    return true;
  }
  assert(false);
}
struct Edge {
  int a, b, c;
  bool operator<(const Edge &t) const { return c > t.c; }
};
int main() {
  iota(par, par + N, 0);
  int n, m;
  cin >> n >> m;
  vector<Edge> edges(m);
  for (int i = 0; i < m; ++i)
    scanf("%d %d %d", &edges[i].a, &edges[i].b, &edges[i].c);
  sort(edges.begin(), edges.end());
  int ans = 0;
  for (auto cur : edges)
    if (unite(cur.a, cur.b)) ans += cur.c;
  cout << ans << '\n';
}
