#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > in[200005];
int dsu[200005], sz[200005];
int f(int x) {
  if (x == dsu[x]) {
    return x;
  }
  return dsu[x] = f(dsu[x]);
}
bool merge(int x, int y) {
  x = f(x), y = f(y);
  if (x != y) {
    dsu[x] = y;
    sz[y] += sz[x];
    return true;
  }
  return false;
}
void solve() {
  int n, m;
  scanf("%d %d ", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d ", &in[i].second.second, &in[i].second.first, &in[i].first);
  }
  for (int i = n; i; --i) {
    dsu[i] = i;
    sz[i] = 1;
  }
  long long ret = 0;
  sort(in, in + m);
  for (int i = m - 1; i >= 0; --i) {
    int a = in[i].second.first, b = in[i].second.second;
    a = f(a), b = f(b);
    int sum = 0;
    if (a != b) {
      sum = sz[a] + sz[b];
    } else {
      sum = sz[a];
    }
    if (sum >= 1) {
      merge(a, b);
      a = f(a);
      --sz[a];
      ret += in[i].first;
    }
  }
  printf("%lld\n", ret);
}
int main() {
  solve();
  return 0;
}
