#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct Edge {
  int u, v, w;
  bool operator<(const Edge &x) const { return w > x.w; }
} edge[N];
int n, m;
int fa[N], t[N];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x * f;
}
int get(int x) {
  if (fa[x] == x) return x;
  return fa[x] = get(fa[x]);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), z = read();
    edge[i] = {x, y, z};
  }
  sort(edge + 1, edge + m + 1);
  for (int i = 1; i <= n; i++) fa[i] = i;
  memset(t, 1, sizeof t);
  long long ans = 0;
  for (int i = 1; i <= m; i++) {
    int u = edge[i].u, v = edge[i].v, w = edge[i].w;
    u = get(u), v = get(v);
    if (u == v) {
      if (t[u])
        ans += w, t[u] = 0;
      else
        continue;
    } else {
      if ((!t[u]) && (!t[v])) continue;
      if ((t[u]) && (!t[v]))
        fa[u] = v, ans += w;
      else if ((!t[u]) && (t[v]))
        fa[v] = u, ans += w;
      else
        fa[u] = v, ans += w;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
