#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
using ll = long long;
int n, m, f[N], cyc[N];
struct Edge {
  int u, v, w;
} e[N];
int getf(int v) { return f[v] == v ? v : f[v] = getf(f[v]); }
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> e[i].u >> e[i].v >> e[i].w;
  sort(e + 1, e + m + 1, [](Edge a, Edge b) { return a.w > b.w; });
  ll ans = 0;
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= m; i++) {
    int u = getf(e[i].u), v = getf(e[i].v);
    if (u == v) {
      if (!cyc[u]) ans += e[i].w, cyc[u] = 1;
      continue;
    }
    if (cyc[u] && cyc[v]) continue;
    f[u] = v;
    cyc[v] |= cyc[u];
    ans += e[i].w;
  }
  cout << ans << endl;
  return 0;
}
