#include <bits/stdc++.h>
using namespace std;
const int MAXM = 2e5;
const int MAXN = 2e5;
int P[MAXN][4];
int idx[MAXM];
bool cmp(int a, int b) { return P[a][2] > P[b][2]; }
int G[MAXN][4];
int getp(int x) {
  if (G[x][0] == x) return x;
  return (G[x][0] = getp(G[x][0]));
}
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    idx[i] = i;
    scanf("%d%d%d", &P[i][0], &P[i][1], &P[i][2]);
    --P[i][0];
    --P[i][1];
    P[i][3] = -1;
  }
  for (int i = 0; i < n; ++i) G[i][0] = -1;
  sort(idx, idx + m, cmp);
  int ans = 0;
  for (int z = 0; z < m;) {
    int i = idx[z];
    if (P[i][3] < 0) {
      bool ok = false;
      for (int zz = 0; zz < 2; ++zz) {
        int id = P[i][zz];
        if (G[id][0] < 0) {
          G[id][0] = id;
          G[id][1] = P[i][zz ^ 1];
          G[id][2] = 1;
          ok = true;
        } else {
          int x = getp(id);
          int v = G[x][1];
          if (G[v][0] < 0) {
            G[v][0] = x;
            G[x][1] = P[i][zz ^ 1];
            G[x][2] += 1;
            ok = true;
          } else {
            int ii = getp(v);
            int jj = getp(id);
            if (ii != jj) {
              G[jj][1] = G[ii][1];
              if (G[ii][2] > G[jj][2]) swap(jj, ii);
              G[jj][0] = ii;
              G[ii][2] += G[jj][2];
              --z;
              break;
            }
          }
        }
        if (ok) {
          int other = P[i][zz ^ 1];
          if (G[other][0] >= 0) {
            int ii = getp(other);
            int jj = getp(id);
            G[jj][1] = G[ii][1];
            if (G[ii][2] > G[jj][2]) swap(jj, ii);
            G[jj][0] = ii;
            G[ii][2] += G[jj][2];
          }
          ans += P[i][2];
          P[i][3] = 1;
          break;
        }
      }
      if (ok) continue;
    }
    ++z;
  }
  printf("%d\n", ans);
}
int main() {
  solve();
  return 0;
}
