#include #define mem(a, b) memset(a, b, sizeof(a)) #define inf (1e9 + 7) using namespace std; int n, m, v[3005]; int main() { while(~scanf("%d%d", &n, &m)) { mem(v, 0); for(int i = 1, a, b, c;i <= m;i++) { scanf("%d%d%d", &a, &b, &c); if(a != b) v[a] += c, v[b] += c; } int ans = inf; for(int i = 1;i <= n;i++) ans = min(ans, v[i]); printf("%d\n", ans); } return 0; }