#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 1000010, P = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int INF = 0xcfcfcfcf;
const double eps = 1e-9, pi = asin(1) * 2;
inline long long read();
inline int ADD(int a, int b) { return a + b >= P ? a + b - P : a + b; }
inline int MINUS(int a, int b) { return a - b < 0 ? a - b + P : a - b; }
int n, m;
struct EDGE {
  int from, to, edge;
} a[N];
inline bool operator<(const EDGE &a, const EDGE &b) { return a.edge > b.edge; }
int fa[N], size[N], num[N];
inline void init() {
  for (int i = 1; i <= n; i++) fa[i] = i, size[i] = 1, num[i] = 0;
}
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline bool unit(int x, int y) {
  x = find(x), y = find(y);
  if (x == y && size[x] == num[x] + 1) {
    num[x]++;
    return true;
  }
  if (size[x] + size[y] == num[x] + num[y]) return false;
  fa[x] = y, size[y] += size[x], num[y] += num[x] + 1;
  return true;
}
inline long long read() {
  long long s = 0;
  bool flag = false;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') flag = true;
  for (; '0' <= ch && ch <= '9'; ch = getchar())
    s = (s << 3) + (s << 1) + (ch ^ '0');
  if (flag) return -s;
  return s;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), z = read();
    a[i] = EDGE{x, y, z};
  }
  sort(a + 1, a + m + 1);
  long long ans = 0;
  init();
  for (int i = 1; i <= m; i++)
    if (unit(a[i].from, a[i].to)) ans += a[i].edge;
  printf("%lld\n", ans);
  return 0;
}
