#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int P = 1e9 + 7;
const int inf = 1e9;
const long long Inf = 1e15;
inline int IN() {
  char ch = getchar();
  int x = 0, f = 0;
  while (ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - 48;
    ch = getchar();
  }
  return f ? (-x) : x;
}
inline int Pow(int x, int y, int p) {
  int an = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) an = (long long)an * x % p;
  return an;
}
void renew(int &x, int y) {
  x += y;
  if (x < 0)
    x += P;
  else if (x >= P)
    x -= P;
}
void setIO(string a) {
  freopen((a + ".in").c_str(), "r", stdin);
  freopen((a + ".out").c_str(), "w", stdout);
}
template <typename T>
inline void chkmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <typename T>
inline void chkmax(T &a, const T &b) {
  if (a < b) a = b;
}
int fa[N], ux[N], vx[N], wx[N], id[N], dj[N], n, m;
int cmp(const int &a, const int &b) { return wx[a] > wx[b]; }
int get(int u) {
  if (fa[u] == u) return u;
  return fa[u] = get(fa[u]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)1; i <= (int)n; i++) fa[i] = i;
  for (int i = (int)1; i <= (int)m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ux[i] = u;
    vx[i] = v;
    wx[i] = w;
    id[i] = i;
  }
  sort(id + 1, id + m + 1, cmp);
  long long ans = 0;
  for (int i = (int)1; i <= (int)m; i++) {
    int du = ux[id[i]], dv = vx[id[i]], dw = wx[id[i]];
    du = get(du);
    dv = get(dv);
    if (du != dv) {
      if (dj[du] && dj[dv]) continue;
      ans += dw;
      fa[du] = dv;
      dj[dv] |= dj[du];
    } else {
      if (dj[dv]) continue;
      dj[dv] = 1;
      ans += dw;
    }
  }
  cout << ans << endl;
  return 0;
}
