#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int _find[222222];
bool has_cycle[222222];
int find(int v) {
  if (_find[v] != v) _find[v] = find(_find[v]);
  return _find[v];
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<pair<int, pair<int, int>>> edges;
  for (int i = 0; i < (M); ++i) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    edges.push_back({w, {a - 1, b - 1}});
  }
  sort(edges.rbegin(), edges.rend());
  int result = 0;
  for (int i = 0; i < (N); ++i) _find[i] = i;
  for (int i = 0; i < (M); ++i) {
    int a = find(edges[i].second.first), b = find(edges[i].second.second);
    if (a != b && (!has_cycle[a] || !has_cycle[b])) {
      result += edges[i].first;
      _find[a] = b;
      has_cycle[b] |= has_cycle[a];
    } else if (a == b && !has_cycle[a]) {
      has_cycle[a] = true;
      result += edges[i].first;
    }
  }
  printf("%d\n", result);
}
