intmain(){ int n, m; while (~scanf("%d%d", &n, &m)) { for (int i = 1; i <= m; i++) scanf("%d%d%lld", &q[i].l, &q[i].r, &q[i].w); sort(q + 1, q + m + 1, cmp); for (int i = 0; i <= n; i++) dp[i] = 1e18; dp[1] = 0; for (int i = 1; i <= m; i++) dp[q[i].r] = min(dp[q[i].r], max(dp[q[i].l], q[i].w)); if (dp[n] == 1e18) puts("invalid data"); else printf("%lld\n", dp[n]); } return0; }