#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, k, w;
int LINK[400005], cost[400005], ed[400005], l[200005];
int ans, v[200005], used[200005], p[200005];
void bd(int x, int y, int z) {
  LINK[w] = l[x];
  l[x] = w;
  ed[w] = y;
  cost[w++] = z;
}
int find(int x) {
  if (p[x] != x) return p[x] = find(p[x]);
  return x;
}
struct node {
  int x, y, val;
  bool operator<(node const& T) const { return T.val > val; }
} A[200005];
int main() {
  memset(l, -1, sizeof(l));
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (m); i++) {
    scanf("%d %d %d", &x, &y, &z);
    bd(x, y, z);
    bd(y, x, z);
    A[i].x = x;
    A[i].y = y;
    A[i].val = z;
  }
  sort(A, A + m);
  for (int i = (1); i <= (n); i++) p[i] = i;
  for (int i = (m - 1); i >= (0); i--) {
    x = find(A[i].x);
    y = find(A[i].y);
    if (x != y && (v[x] == 0 || v[y] == 0)) {
      p[x] = y;
      v[y] = max(v[x], v[y]);
      ans += A[i].val;
    } else if (x == y && v[x] == 0) {
      v[x] = 1;
      ans += A[i].val;
    }
  }
  printf("%d\n", ans);
  return 0;
}
