#include <bits/stdc++.h>
using namespace std;
int d[20][20];
int main() {
  int n, m;
  cin >> n >> m;
  int a, b, c;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      d[i][j] = 1e9;
    }
    d[i][i] = 0;
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d", &a, &b, &c);
    d[a][b] = d[b][a] = c;
  }
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int tot = 0;
  int ma = 0;
  for (int i = 1; i < n; ++i) {
    if (d[i][n] < 1e9) {
      if (d[1][i] < 1e9) {
        ma = max(ma, d[i][n]);
        tot += d[i][n];
      }
    }
  }
  cout << tot - ma << endl;
}
