#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int W[100][100];
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      W[i][j] = INT_MAX;
    }
  }
  for (int i = 0; i < m; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    W[s][t] = w;
    W[t][s] = w;
  }
  int o = 0;
  int mark[100][100] = {};
  for (int i = 0; i < n; i++) {
    int pie[100];
    for (int p = 0; p < 100; p++) {
      pie[p] = -1;
    }
    int visited[100] = {};
    vector<pair<int, int>> pq;
    for (int k = 0; k < n; k++) {
      int d = (k == i) ? 0 : INT_MAX;
      pq.push_back(make_pair(d, k));
    }
    vector<pair<int, int>> pq_copy(pq);
    make_heap(pq.begin(), pq.end(), greater<pair<int, int>>());
    while (pq.size() > 0) {
      pair<int, int> s = pq.front();
      pop_heap(pq.begin(), pq.end(), greater<pair<int, int>>());
      pq.pop_back();
      visited[s.second] = 1;
      for (int t = 0; t < 100; t++) {
        if (W[s.second][t] != INT_MAX && !visited[t]) {
          if (s.first + W[s.second][t] < pq_copy[t].first) {
            pq_copy[t].first = s.first + W[s.second][t];
            pie[t] = s.second;
          }
        }
      }
      for (auto a : pq) {
        a.first = pq_copy[a.second].first;
      }
      make_heap(pq.begin(), pq.end(), greater<pair<int, int>>());
    }
  }
  cout << 0 << endl;
  return 0;
}
