#include <bits/stdc++.h>
using namespace std;
struct st {
  int w, x, y;
  bool operator<(const st &a) const { return w < a.w; }
} d[200010];
int n, m;
int p[200010];
int chk[200010];
int par(int x) {
  if (p[x] == x)
    return x;
  else
    return p[x] = par(p[x]);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> d[i].x >> d[i].y >> d[i].w;
  sort(d + 1, d + m + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = m; i >= 1; i--) {
    int x = d[i].x;
    int y = d[i].y;
    x = par(x);
    y = par(y);
    if (x != y && chk[x] + chk[y] <= 1) {
      p[x] = y;
      chk[y] += chk[x];
      ans += d[i].w;
    } else if (x == y && chk[x] == 0) {
      chk[x] = 1;
      ans += d[i].w;
    }
  }
  cout << ans << endl;
  return 0;
}
