#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
int par[MAX];
bool cyc[MAX];
int GetPar(int vr) { return par[vr] == vr ? vr : par[vr] = GetPar(par[vr]); }
void Merge(int a, int b) {
  a = GetPar(a), b = GetPar(b);
  bool has_cyc = (cyc[a] || cyc[b]);
  par[a] = b;
  cyc[a] = cyc[b] = has_cyc;
}
int n, m;
vector<pair<int, pair<int, int>>> edj;
int ans = 0;
int main() {
  for (int i = 0; i < MAX; ++i) par[i] = i;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    --a, --b;
    edj.push_back(make_pair(w, make_pair(a, b)));
  }
  sort(edj.begin(), edj.end()), reverse(edj.begin(), edj.end());
  for (int i = 0; i < ((int)(edj).size()); ++i) {
    int w = edj[i].first;
    int a = edj[i].second.first;
    int b = edj[i].second.second;
    if (GetPar(a) != GetPar(b)) {
      if (!cyc[GetPar(a)] || !cyc[GetPar(b)]) {
        Merge(a, b);
        ans += w;
      }
    } else if (!cyc[GetPar(a)]) {
      cyc[GetPar(a)] = true;
      ans += w;
    }
  }
  printf("%d\n", ans);
  return 0;
}
