#include <bits/stdc++.h>
using namespace std;
struct pr {
  int x, y, w;
} a[200001];
int now[200001], fa[200001];
bool vis[200001];
bool cmp(pr xx, pr yy) { return xx.w > yy.w; }
int findfa(int x) { return fa[x] == x ? x : fa[x] = findfa(fa[x]); }
int main() {
  int n, m;
  cin >> n >> m;
  for (register int i = 1; i <= m; i++) cin >> a[i].x >> a[i].y >> a[i].w;
  sort(a + 1, a + m + 1, cmp);
  for (register int i = 1; i <= n; i++) fa[i] = i;
  int ans = 0;
  for (register int i = 1; i <= m; i++) {
    int x = findfa(a[i].x), y = findfa(a[i].y);
    if (vis[x] && vis[y])
      continue;
    else if (vis[x])
      vis[y] = true, ans += a[i].w;
    else if (vis[y])
      vis[x] = true, ans += a[i].w;
    else if (x == y)
      vis[x] = true, ans += a[i].w;
    else
      ans += a[i].w, fa[y] = x;
  }
  cout << ans << endl;
  return 0;
}
