#include <bits/stdc++.h>
using namespace std;
namespace INPUT {
const int L = 1 << 15;
char _buf[L], *S, *T, c;
char _gc() {
  if (S == T) {
    T = (S = _buf) + fread(_buf, 1, L, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
void readi(int &X) {
  for (c = _gc(); c < '0' || c > '9'; c = _gc())
    ;
  X = c & 15;
  for (c = _gc(); c >= '0' && c <= '9'; X = X * 10 + (c & 15), c = _gc())
    ;
}
}  // namespace INPUT
using INPUT::readi;
const int Maxn = 2E5 + 5;
int N, M;
struct Edge {
  int a, b, w;
} e[Maxn];
int T[Maxn];
bool mrk[Maxn];
long long Ans;
bool cmp(Edge x, Edge y) { return x.w > y.w; }
int Find(int X) {
  if (T[X] == -1) return X;
  return T[X] = Find(T[X]);
}
int main() {
  readi(N), readi(M);
  for (int i = 1; i <= M; ++i) readi(e[i].a), readi(e[i].b), readi(e[i].w);
  sort(e + 1, e + M + 1, cmp);
  memset(T, -1, sizeof(T)), memset(mrk, true, sizeof(mrk));
  for (int i = 1; i <= M; ++i) {
    int Fa = Find(e[i].a);
    int Fb = Find(e[i].b);
    if (!mrk[Fa] && !mrk[Fb]) continue;
    Ans += e[i].w;
    if (mrk[Fa] && mrk[Fb]) {
      if (Fb != Fa)
        T[Fb] = Fa;
      else
        mrk[Fa] = false;
      continue;
    }
    if (mrk[Fb]) swap(Fa, Fb);
    mrk[Fa] = false;
  }
  cout << Ans;
  return 0;
}
