#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int a[200105], b[200105], w[200105];
bool vis[200105];
vector<pair<int, int> > vp;
int f[200105];
int ff(int x) { return x == f[x] ? x : f[x] = ff(f[x]); }
void fmain(int ID) {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(m); (i)++) scanf("%d%d%d", a + i, b + i, w + i);
  for (int(i) = 1; (i) <= (int)(m); (i)++) vp.push_back({-w[i], i});
  for (int(i) = 1; (i) <= (int)(n); (i)++) f[i] = i;
  sort(vp.begin(), vp.end());
  int ans = 0;
  for (int(i) = 0; (i) < (int)(m); (i)++) {
    int eid = vp[i].second;
    int u = a[eid], v = b[eid];
    int fu = ff(u), fv = ff(v);
    if (vis[fu] && vis[fv]) continue;
    if (fu == fv)
      vis[fu] = 1;
    else {
      f[fu] = fv;
      vis[fv] |= vis[fu];
    }
    ans += w[eid];
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
