#include <bits/stdc++.h>
using namespace std;
const int N = 210000;
struct Edge {
  int u, v, w;
  bool operator<(const Edge &a) const { return w > a.w; }
} e[N];
int belong[N], d[N], n, m, sum;
int Find(int u) {
  if (belong[u] != u) belong[u] = Find(belong[u]);
  return belong[u];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    belong[i] = i;
    d[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].w);
  }
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; i++) {
    int x = Find(e[i].u), y = Find(e[i].v);
    if (x != y && (d[x] || d[y])) {
      belong[x] = y;
      sum += e[i].w;
      d[y] = d[x] & d[y];
    } else if (x == y && d[x]) {
      d[x] = 0;
      sum += e[i].w;
    }
  }
  printf("%d\n", sum);
  return 0;
}
