#include <iostream>
#include <fstream>
#define FIN "hamilton.in"
#define FOUT "hamilton.out"
using namespace std;
const int INF = 100000000;
const int MAXN = 20;
int n, m, sol;
int Cost[ MAXN ][ MAXN ],
P[ MAXN ],
Used[ MAXN ];
void back(int level) {
if(level > n) {
int summa = Cost[P[n]][P[1]];
for(int i = 1; i < n; ++i) {
summa += Cost[ P[i] ][ P[i+1] ];
}
sol = min(sol, summa);
return;
}
for(int i = 0; i < n; ++i) {
if( !Used[i] ) {
P[ level ] = i;
Used[i] = 1;
back(level + 1);
Used[i] = 0;
}
}
}
int main(int argc, char const *argv[]) {
int x,
y;
ifstream fin(FIN);
ofstream fout(FOUT);
cin>>n>>m;
sol = INF;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; ++j)
Cost[i][j] = INF;
while( m-- ){
cin>>x>>y;
cin>>Cost[x][y];
}
back(1);
if(sol == INF) {
cout<<"Nu exista solutie";
} else {
cout<<sol;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2RlZmluZSBGSU4gImhhbWlsdG9uLmluIgojZGVmaW5lIEZPVVQgImhhbWlsdG9uLm91dCIKIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmNvbnN0IGludCBJTkYgPSAxMDAwMDAwMDA7CmNvbnN0IGludCBNQVhOID0gMjA7CiAKaW50IG4sIG0sIHNvbDsKaW50IENvc3RbIE1BWE4gXVsgTUFYTiBdLAogICAgUFsgTUFYTiBdLAogICAgVXNlZFsgTUFYTiBdOwogCnZvaWQgYmFjayhpbnQgbGV2ZWwpIHsKIAogICAgIGlmKGxldmVsID4gbikgewogCiAgICAgICAgICAgaW50IHN1bW1hID0gQ29zdFtQW25dXVtQWzFdXTsKIAogICAgICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPCBuOyArK2kpIHsKIAogICAgICAgICAgICAgICBzdW1tYSArPSBDb3N0WyBQW2ldIF1bIFBbaSsxXSBdOwogICAgICAgICAgIH0KIAogICAgICAgICAgIHNvbCA9IG1pbihzb2wsIHN1bW1hKTsKIAogICAgICAgICAgIHJldHVybjsKIAogICAgIH0KIAogICAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IG47ICsraSkgewogCiAgICAgICAgICAgICAgaWYoICFVc2VkW2ldICkgewogICAgICAgICAgICAgICAgICAgUFsgbGV2ZWwgXSA9IGk7CiAgICAgICAgICAgICAgICAgICBVc2VkW2ldID0gMTsKICAgICAgICAgICAgICAgICAgIGJhY2sobGV2ZWwgKyAxKTsKICAgICAgICAgICAgICAgICAgIFVzZWRbaV0gPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgIH0KIAp9CiAKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgY29uc3QgKmFyZ3ZbXSkgewogCiAgICBpbnQgeCwKICAgICAgICB5OwogCiAgICBpZnN0cmVhbSBmaW4oRklOKTsKIAogICAgb2ZzdHJlYW0gZm91dChGT1VUKTsKIAogICAgY2luPj5uPj5tOwogCiAgICBzb2wgPSBJTkY7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBuOyArK2opCiAgICAgICAgICAgIENvc3RbaV1bal0gPSBJTkY7CiAKICAgIHdoaWxlKCBtLS0gKXsKICAgICAgICBjaW4+Png+Pnk7CiAgICAgICAgY2luPj5Db3N0W3hdW3ldOwogICAgfQogCiAgICBiYWNrKDEpOwogCiAgICBpZihzb2wgPT0gSU5GKSB7CiAgICAgIGNvdXQ8PCJOdSBleGlzdGEgc29sdXRpZSI7CiAgICB9IGVsc2UgewogICAgICBjb3V0PDxzb2w7CiAgICB9CiAKICByZXR1cm4gMDsKfQ==