#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FORD(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; FOR(_, l, r) DB1(A, _); cerr << '\n';}
#define sz(x) ((int) (x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef array<int, 3> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vl;
const int N = 5002, INF = 1e9 + 7;
int n, m, edgeW[N];
vii g[N];
int d[N];
bool done[N];
int main()
{
#ifdef HynDuf
freopen("inp.txt", "r", stdin);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n >> m;
ll tot = 0;
FOR(i, 1, m)
{
int u, v, w;
cin >> u >> v >> w;
g[u].eb(v, w);
g[v].eb(u, w);
tot += w;
}
FOR(i, 2, n) d[i] = INF;
FOR(i, 1, n)
{
int mn = INF;
int u = 0;
FOR(v, 1, n) if (!done[v] && mn > d[v]) mn = d[v], u = v;
if (u == 0) break;
done[u] = 1;
for (auto &v : g[u]) if (!done[v.F] && d[v.F] > v.S)
d[v.F] = v.S, edgeW[v.F] = v.S;
}
FOR(i, 1, n) tot -= edgeW[i];
cout << tot;
return 0;
}
I2luY2x1ZGUgPGJ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