#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct DY {
  int u, v, w;
} e[maxn];
int fa[maxn], f[maxn];
int Find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = Find(fa[x]);
}
bool cmp(DY x, DY y) { return x.w > y.w; }
template <typename T>
void read(T &x) {
  x = 0;
  int flag = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x = x * flag;
}
int n, m, a[maxn], u, v, w, ans;
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    read(e[i].u);
    read(e[i].v);
    read(e[i].w);
  }
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    u = e[i].u;
    v = e[i].v;
    w = e[i].w;
    int x = Find(u), y = Find(v);
    if (x == y && f[x] != 1) {
      f[x] = 1;
      ans += w;
    }
    if (x != y && f[x] + f[y] <= 1) {
      fa[x] = y;
      f[y] += f[x];
      ans += w;
    }
  }
  printf("%d", ans);
  return 0;
}
