#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1LL;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
template <class T>
inline void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void chmin(T &a, T b) {
  if (a > b) a = b;
}
inline void swap(int &a, int &b) {
  int c = a;
  a = b;
  b = c;
}
using namespace std;
const int N = 2e6 + 10;
struct node {
  int u, v, w;
  bool operator<(const node b) const { return w > b.w; }
} e[N << 1];
int n, m, fa[N], s[N];
inline int find(int x) {
  while (x ^ fa[x]) x = fa[x] = fa[fa[x]];
  return x;
}
int ans;
int main() {
  n = read();
  m = read();
  for (int i = (1); i <= (n); ++i) fa[i] = i;
  for (int i = (1); i <= (m); ++i)
    e[i].u = read(), e[i].v = read(), e[i].w = read();
  sort(e + 1, e + m + 1);
  for (int i = (1); i <= (m); ++i) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    int fu = find(u), fv = find(v);
    if (fu ^ fv) {
      if (s[fu] && s[fv]) continue;
      fa[fu] = fv;
      s[fv] |= s[fu];
      ans += w;
    } else {
      if (!s[fu]) s[fu] = 1, ans += w;
    }
  }
  return printf("%d\n", ans), 0;
}
