#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int INF = 0x3f3f3f3f;
template <class T>
inline bool RD(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1, ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void PT(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) PT(x / 10);
  putchar(x % 10 + '0');
}
const int N = 2e5 + 100;
int fa[N];
bool flag[N];
int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); }
vector<pair<int, pair<int, int> > > es;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) fa[i] = i;
  es.resize(m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &es[i].second.first, &es[i].second.second, &es[i].first);
  }
  sort(es.begin(), es.end(), greater<pair<int, pair<int, int> > >());
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int u = es[i].second.first, v = es[i].second.second;
    if (getf(u) == getf(v)) {
      if (flag[fa[u]]) continue;
      flag[fa[u]] = true;
      ans += es[i].first;
    } else {
      if (flag[fa[u]] && flag[fa[v]]) continue;
      ans += es[i].first;
      flag[fa[v]] |= flag[fa[u]];
      fa[fa[u]] = fa[v];
    }
  }
  printf("%d\n", ans);
}
