#include <bits/stdc++.h>
using namespace std;
vector<tuple<int, int, int>> edl;
bool full[200005];
int from[200005];
int _find(int first) {
  if (from[first] == first) {
    return first;
  }
  return from[first] = _find(from[first]);
}
void joint(int first, int second) {
  first = _find(first);
  second = _find(second);
  from[first] = second;
  full[second] |= full[first];
}
int main() {
  int t, i, j, n, m, first, second, w, res = 0;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    from[i] = i;
  }
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d", &first, &second, &w);
    edl.emplace_back(w, first, second);
  }
  sort(edl.begin(), edl.end());
  for (i = edl.size() - 1; i >= 0; i--) {
    tie(w, first, second) = edl[i];
    first = _find(first);
    second = _find(second);
    if (full[first] && full[second]) {
      continue;
    }
    if (first == second) {
      full[first] = true;
    } else {
      joint(first, second);
    }
    res += w;
  }
  printf("%d\n", res);
  return 0;
}
