#include using namespace std; int main() { int n,m; while(cin >> n >> m){ long long a[3005] = {0}; while(m--){ int num1,num2,num3; cin >> num1 >> num2 >> num3; if(num1 == num2){ continue; } a[num1] += num3; a[num2] += num3; } long long mi = 10000000000; for(int i = 1;i <= n;i++){ mi = min(mi,a[i]); } cout << mi << endl; } return 0; }