#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <class T>
int size(T &&x) {
  return int(x.size());
}
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <class T>
auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
  out << '{';
  for (auto it = x.begin(); it != x.end(); ++it)
    out << *it << (it == prev(x.end()) ? "" : ", ");
  return out << '}';
}
void dump() {}
template <class T, class... Args>
void dump(T &&x, Args... args) {
  cerr << x << ";  ";
  dump(args...);
}
mt19937_64 rng(0);
int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
vector<int> lead;
int find(int v) {
  if (v == lead[v]) return v;
  return lead[v] = find(lead[v]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int, int>> edges;
  for (int i = (0); i <= ((m)-1); ++i) {
    int a, b, w;
    cin >> a >> b >> w;
    --a, --b;
    edges.emplace_back(make_tuple(w, i, a, b));
  }
  sort(edges.rbegin(), edges.rend());
  lead.resize(n);
  iota(lead.begin(), lead.end(), 0);
  vector<bool> lead_has_cycle(n, false);
  int answer = 0;
  for (auto [weight, from, to1, to2] : edges) {
    0 && cerr;
    to1 = find(to1);
    to2 = find(to2);
    if (to1 == to2 and not lead_has_cycle[to1]) {
      lead_has_cycle[to1] = true;
      answer += weight;
    } else if (to1 != to2 and
               int(lead_has_cycle[to1]) + int(lead_has_cycle[to2]) <= 1) {
      bool has_cycle = lead_has_cycle[to1] or lead_has_cycle[to2];
      lead[to1] = to2;
      lead_has_cycle[to2] = has_cycle;
      answer += weight;
    }
  }
  cout << answer << '\n';
}
