#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T maxs(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T mins(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long maxn = 2000005;
long long p[maxn];
long long sz[maxn];
long long cyc[maxn];
void clear(long long n = maxn) {
  for (long long i = 0; i < maxn; i++) p[i] = i, sz[i] = 1, cyc[i] = 0;
}
long long root(long long first) {
  while (first != p[first]) {
    p[first] = p[p[first]];
    first = p[first];
  }
  return first;
}
bool merge(long long first, long long second) {
  long long p1 = root(first);
  long long p2 = root(second);
  if (p1 == p2) {
    if (cyc[p1] == 0) {
      cyc[p1] = 1;
      return 1;
    } else {
      return 0;
    }
  }
  if (sz[p1] < sz[p2]) swap(p1, p2);
  if (cyc[p1] and cyc[p2]) {
    return 0;
  }
  p[p2] = p1;
  sz[p1] += sz[p2];
  cyc[p1] |= cyc[p2];
  return 1;
}
long long solve() {
  long long n;
  cin >> n;
  clear();
  long long m;
  cin >> m;
  vector<pair<long long, pair<long long, long long>>> edges;
  for (long long i = 0; i < m; i++) {
    long long a, b, w;
    cin >> a >> b >> w;
    edges.push_back({-w, {a, b}});
  }
  sort(edges.begin(), edges.end());
  long long ans = 0;
  for (auto i : edges) {
    if (merge(i.second.first, i.second.second)) {
      ans -= i.first;
    }
  }
  cout << ans << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
