#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename t>
using V = vector<t>;
template <typename t>
void print(ostream& os, const t& a) {
  os << a << '\n';
}
template <typename t, typename... A>
void print(ostream& os, const t& a, A&&... b) {
  os << a << ' ';
  print(os, b...);
}
struct Node {
  bool fl = true;
  int siz = 1, lid;
};
struct Princess {
  int a, b, w;
};
inline bool operator<(const Princess& a, const Princess& b) {
  return a.w < b.w;
}
int n, m;
V<Node> gr;
V<Princess> tr;
inline int find(int v) {
  int k = gr[v].lid;
  return gr[k].lid == k ? k : gr[v].lid = find(k);
}
inline bool free(int v) { return gr[find(v)].fl; }
inline void join(int v, int w) {
  ;
  v = find(v);
  w = find(w);
  if (v == w) gr[v].fl = false;
  if (gr[v].fl == false or gr[w].fl == false) {
    ;
    gr[find(v)].fl = gr[find(w)].fl = false;
    return;
  }
  if (gr[v].siz < gr[w].siz) swap(v, w);
  gr[v].siz += gr[w].siz;
  gr[w].lid = v;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> m >> n;
  tr.resize(n);
  gr.resize(m + 1);
  for (int i = 1; i <= m; ++i) gr[i].lid = i;
  for (auto& p : tr) cin >> p.a >> p.b >> p.w;
  sort(begin(tr), end(tr));
  reverse(begin(tr), end(tr));
  ll res = 0;
  for (auto& p : tr)
    if (free(p.a) or free(p.b)) {
      res += p.w;
      join(p.a, p.b);
    }
  print(cout, res);
}
