#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct Edge {
  int u, v, w;
} E[N];
int n, m;
int fa[N], vis[N];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
inline bool cmp(Edge a, Edge b) { return a.w > b.w; }
inline int getroot(int x) {
  if (fa[x] == x)
    return x;
  else
    return fa[x] = getroot(fa[x]);
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    read(u);
    read(v);
    read(w);
    E[i] = (Edge){u, v, w};
  }
  sort(E + 1, E + m + 1, cmp);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    int bu = getroot(E[i].u), bv = getroot(E[i].v);
    if (vis[bu] && vis[bv]) continue;
    if (bu == bv && !vis[bu]) {
      vis[bu] = 1;
      ans += (long long)E[i].w;
      continue;
    } else if (bu == bv)
      continue;
    ans += (long long)E[i].w;
    if (vis[bu])
      fa[bv] = bu;
    else
      fa[bu] = bv;
  }
  printf("%lld\n", ans);
  return 0;
}
