#include <bits/stdc++.h>
using namespace std;
struct People {
  int x, y, d;
} p[200001];
int n, m, ans;
int fa[200001], dis[200001];
inline bool cmp(People a, People b) { return a.d > b.d; }
int find(int x) {
  if (x == fa[x])
    return fa[x];
  else
    return fa[x] = find(fa[x]);
}
int main() {
  cin >> n >> m;
  for (int i = 1, x, y, d; i <= m; i++)
    cin >> x >> y >> d, p[i].x = x, p[i].y = y, p[i].d = d;
  sort(p + 1, p + m + 1, cmp);
  for (int i = 1; i <= n; i++) fa[i] = i, dis[i] = 1;
  for (int i = 1; i <= m; i++) {
    int x = find(p[i].x);
    int y = find(p[i].y);
    if (x != y && (dis[x] != 0 || dis[y] != 0))
      fa[y] = x, ans += p[i].d, dis[x] = dis[x] & dis[y];
    else if (x == y && dis[x])
      dis[x] = 0, ans += p[i].d;
  }
  cout << ans;
}
