import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.AbstractCollection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        int tot;

        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), m = s.nextInt(), x, y, xx = 0, yy = 0;
            long l;
            ArrayList<pair<Integer, Long>>[] a = new ArrayList[n];
            PriorityQueue<pair<Long, pair<Integer, Integer>>> pq = new PriorityQueue<>();
            for (int i = 0; i < n; i++) {
                a[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; i++) {
                x = s.nextInt() - 1;
                y = s.nextInt() - 1;
                if (i == 0) {
                    xx = x;
                    yy = y;
                }
                l = s.nextInt();
                a[x].add(new pair(y, l));
                a[y].add(new pair(x, l));
                pq.add(new pair(l, new pair(x, y)));
            }
            boolean[] vis = new boolean[n];
            check(a, vis, xx, yy);
            if (tot == 2) {
                w.println((int) 1e9);
            } else {
                dsu d = new dsu(n);
                while (!pq.isEmpty()) {
                    pair<Long, pair<Integer, Integer>> pp = pq.poll();
                    if (pp.y.x == xx && pp.y.y == yy) continue;
                    if (d.getPar(pp.y.x) != d.getPar(pp.y.y)) {
                        d.unite(pp.y.x, pp.y.y);
                        if (d.getPar(xx) == d.getPar(yy)) {
                            w.println(pp.x);
                            return;
                        }
                    }
                }
                w.println((int) 1e9);
            }
        }

        void check(ArrayList<pair<Integer, Long>>[] a, boolean[] vis, int cur, int to) {
            vis[cur] = true;
            if (cur == to) {
                tot++;
                return;
            }
            for (pair<Integer, Long> i : a[cur]) {
                if (!vis[i.x]) {
                    check(a, vis, i.x, to);
                    if (tot == 2) {
                        return;
                    }
                }
            }
            vis[cur] = false;
        }

    }

    static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>> {
        public U x;
        public V y;

        public pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(pair<U, V> other) {
            if (this.x.compareTo(other.x) != 0) return this.x.compareTo(other.x);
            return this.y.compareTo(other.y);
        }

        public String toString() {
            return x.toString() + " " + y.toString();
        }

        public boolean equals(Object obj) {
            if (this.getClass() != obj.getClass()) return false;
            pair<U, V> other = (pair<U, V>) obj;
            return this.x.equals(other.x) && this.y.equals(other.y);
        }

        public int hashCode() {
            return toString().hashCode();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class dsu {
        public int con;
        public int[] par;
        public int[] sz;

        public dsu(int n) {
            par = new int[n];
            sz = new int[n];
            for (int i = 0; i < n; i++) {
                par[i] = i;
                sz[i] = 1;
            }
            con = n;
        }

        public int getPar(int k) {
            while (k != par[k]) {
                par[k] = par[par[k]];
                k = par[k];
            }
            return k;
        }

        public void unite(int u, int v) {
            int par1 = getPar(u), par2 = getPar(v);
            if (par1 == par2)
                return;

            con--;
            if (sz[par1] > sz[par2]) {
                int tem = par1;
                par1 = par2;
                par2 = tem;
            }
            sz[par2] += sz[par1];
            sz[par1] = 0;
            par[par1] = par[par2];
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.AbstractCollection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), m = s.nextInt(), x, y, xx = 0, yy = 0;
            long l;
            ArrayList<pair<Integer, Long>>[] a = new ArrayList[n];
            PriorityQueue<pair<Long, pair<Integer, Integer>>> pq = new PriorityQueue<>();
            for (int i = 0; i < n; i++) {
                a[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; i++) {
                x = s.nextInt() - 1;
                y = s.nextInt() - 1;
                if (i == 0) {
                    xx = x;
                    yy = y;
                }
                l = s.nextInt();
                a[x].add(new pair(y, l));
                a[y].add(new pair(x, l));
                pq.add(new pair(l, new pair(x, y)));
            }
            boolean[] vis = new boolean[n];
            dsu d = new dsu(n);
            while (!pq.isEmpty()) {
                pair<Long, pair<Integer, Integer>> pp = pq.poll();
                if (pp.y.x == xx && pp.y.y == yy) continue;
                if (d.getPar(pp.y.x) != d.getPar(pp.y.y)) {
                    d.unite(pp.y.x, pp.y.y);
                    if (d.getPar(xx) == d.getPar(yy)) {
                        w.println(pp.x);
                        return;
                    }
                }
            }
            w.println((int) 1e9);
        }

    }

    static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>> {
        public U x;
        public V y;

        public pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(pair<U, V> other) {
            if (this.x.compareTo(other.x) != 0) return this.x.compareTo(other.x);
            return this.y.compareTo(other.y);
        }

        public String toString() {
            return x.toString() + " " + y.toString();
        }

        public boolean equals(Object obj) {
            if (this.getClass() != obj.getClass()) return false;
            pair<U, V> other = (pair<U, V>) obj;
            return this.x.equals(other.x) && this.y.equals(other.y);
        }

        public int hashCode() {
            return toString().hashCode();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class dsu {
        public int con;
        public int[] par;
        public int[] sz;

        public dsu(int n) {
            par = new int[n];
            sz = new int[n];
            for (int i = 0; i < n; i++) {
                par[i] = i;
                sz[i] = 1;
            }
            con = n;
        }

        public int getPar(int k) {
            while (k != par[k]) {
                par[k] = par[par[k]];
                k = par[k];
            }
            return k;
        }

        public void unite(int u, int v) {
            int par1 = getPar(u), par2 = getPar(v);
            if (par1 == par2)
                return;

            con--;
            if (sz[par1] > sz[par2]) {
                int tem = par1;
                par1 = par2;
                par2 = tem;
            }
            sz[par2] += sz[par1];
            sz[par1] = 0;
            par[par1] = par[par2];
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.AbstractCollection;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), m = s.nextInt(), x, y, xx = 0, yy = 0, l;
            PriorityQueue<pair<Integer, pair<Integer, Integer>>> pq = new PriorityQueue<>();
            for (int i = 0; i < m; i++) {
                x = s.nextInt() - 1;
                y = s.nextInt() - 1;
                if (i == 0) {
                    xx = x;
                    yy = y;
                }
                l = s.nextInt();
                pq.add(new pair(l, new pair(x, y)));
            }
            boolean[] vis = new boolean[n];
            dsu d = new dsu(n);
            while (!pq.isEmpty()) {
                pair<Integer, pair<Integer, Integer>> pp = pq.poll();
                if (pp.y.x == xx && pp.y.y == yy) continue;
                if (d.getPar(pp.y.x) != d.getPar(pp.y.y)) {
                    d.unite(pp.y.x, pp.y.y);
                    if (d.getPar(xx) == d.getPar(yy)) {
                        w.println(pp.x);
                        return;
                    }
                }
            }
            w.println((int) 1e9);
        }

    }

    static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>> {
        public U x;
        public V y;

        public pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(pair<U, V> other) {
            if (this.x.compareTo(other.x) != 0) return this.x.compareTo(other.x);
            return this.y.compareTo(other.y);
        }

        public String toString() {
            return x.toString() + " " + y.toString();
        }

        public boolean equals(Object obj) {
            if (this.getClass() != obj.getClass()) return false;
            pair<U, V> other = (pair<U, V>) obj;
            return this.x.equals(other.x) && this.y.equals(other.y);
        }

        public int hashCode() {
            return toString().hashCode();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class dsu {
        public int con;
        public int[] par;
        public int[] sz;

        public dsu(int n) {
            par = new int[n];
            sz = new int[n];
            for (int i = 0; i < n; i++) {
                par[i] = i;
                sz[i] = 1;
            }
            con = n;
        }

        public int getPar(int k) {
            while (k != par[k]) {
                par[k] = par[par[k]];
                k = par[k];
            }
            return k;
        }

        public void unite(int u, int v) {
            int par1 = getPar(u), par2 = getPar(v);
            if (par1 == par2)
                return;

            con--;
            if (sz[par1] > sz[par2]) {
                int tem = par1;
                par1 = par2;
                par2 = tem;
            }
            sz[par2] += sz[par1];
            sz[par1] = 0;
            par[par1] = par[par2];
        }

    }
}


import java.io.*;
import java.util.*;

public class D {

	static class Edge implements Comparable<Edge> {
		int v, u, cost, idx;

		public Edge(int v, int u, int cost, int idx) {
			this.v = v;
			this.u = u;
			this.cost = cost;
			this.idx = idx;
		}

		@Override
		public int compareTo(Edge o) {
			return Integer.compare(cost, o.cost);
		}
	}

	int[] head;
	int[] next;
	Edge[] to;

	void addEdge(Edge e, int pos) {
		to[2 * pos] = e;
		next[2 * pos] = head[e.v];
		head[e.v] = 2 * pos;

		to[2 * pos + 1] = e;
		next[2 * pos + 1] = head[e.u];
		head[e.u] = 2 * pos + 1;
	}

	int[] p;

	static final int INF = Integer.MAX_VALUE / 2;

	void submit() {
		int n = nextInt();
		int m = nextInt();

		Edge[] es = new Edge[m];

		for (int i = 0; i < m; i++) {
			int v = nextInt() - 1;
			int u = nextInt() - 1;
			int cost = nextInt();
			es[i] = new Edge(v, u, cost + 1, i);
		}

		Arrays.sort(es);
		p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = i;
		}

		Arrays.sort(es);

		Edge[] mst = new Edge[n - 1];
		int ptr = 0;

		Edge[] nonMst = new Edge[m - n + 1];
		int ptrNonMst = 0;
 		boolean [] inMst = new boolean[m];
		for (Edge e : es) {
			if (unite(e.v, e.u)) {
//				System.err.println(e.v + " " + e.u);
				mst[ptr++] = e;
				inMst[e.idx] = true;
			} else {
				nonMst[ptrNonMst++] = e;
			}
		}

		head = new int[n];
		Arrays.fill(head, -1);
		next = new int[2 * n - 2];
		to = new Edge[2 * n - 2];

		for (int i = 0; i < n - 1; i++) {
			addEdge(mst[i], i);
		}

		time = 0;
		depth = new int[n];
		tIn = new int[n];
		tOut = new int[n];
		up = new int[LOG][n];
		maxCostUp = new int[LOG][n];

		markMinUp = new int[LOG][n];
		for (int i = 0; i < LOG; i++) {
			Arrays.fill(markMinUp[i], INF);
		}

		dfs1(0, 0, -1);

		ans = new int[m];

		for (Edge e : nonMst) {
			int v = e.v;
			int u = e.u;
			int mid = lca(v, u);

			ans[e.idx] = Math.max(getAnsNoMst(v, mid, e.cost),
					getAnsNoMst(u, mid, e.cost)) - 1;
		}

		dfs2(0, 0, -1);
 		for(int i = 0; i < m; i++){
		// for (int x : ans) {
			int x = ans[i];
			// if(inMst[i] && x != -1) x = Integer.max(x, es[i].cost - 1);
			if(x == -1)
				out.println(1000*1000*1000);
			else out.println(x);
			break;
		}
		// out.println();
	}

	void dfs2(int v, int p, int pEdge) {

		for (int idx = head[v]; idx >= 0; idx = next[idx]) {
			Edge e = to[idx];
			int u = e.v ^ e.u ^ v;
			if (u == p) {
				continue;
			}

			dfs2(u, v, e.idx);
		}

		if (pEdge == -1) {
			return;
		}

		int markSoFar = INF;

		for (int i = LOG - 1; i > 0; i--) {
			markSoFar = Math.min(markSoFar, markMinUp[i][v]);
			int mid = up[i - 1][v];
			markMinUp[i - 1][mid] = Math.min(markMinUp[i - 1][mid], markSoFar);
		}
		markSoFar = Math.min(markSoFar, markMinUp[0][v]);
		ans[pEdge] = markSoFar == INF ? -1 : markSoFar - 1;
	}

	int[] ans;

	int getAnsNoMst(int v, int u, int mark) {
		int ret = -1;
		for (int i = LOG - 1; i >= 0; i--) {
			int to = up[i][v];
			if (isAnc(u, to)) {
				ret = Math.max(ret, maxCostUp[i][v]);

				markMinUp[i][v] = Math.min(markMinUp[i][v], mark);
				v = to;
			}
		}
		return ret;
	}

	static final int LOG = 18;

	int[] tIn, tOut;
	int time;
	int[][] up;
	int[][] maxCostUp;
	int[] depth;
	int[][] markMinUp;

	boolean isAnc(int v, int u) {
		return tIn[v] <= tIn[u] && tOut[u] <= tOut[v];
	}

	int lca(int v, int u) {
		if (isAnc(v, u)) {
			return v;
		}
		if (isAnc(u, v)) {
			return u;
		}
		for (int i = LOG - 1; i >= 0; i--) {
			int to = up[i][v];
			if (!isAnc(to, u)) {
				v = to;
			}
		}
		return up[0][v];
	}

	void dfs1(int v, int p, int costUp) {
		up[0][v] = p;
		maxCostUp[0][v] = costUp;
		for (int i = 1; i < LOG; i++) {
			int mid = up[i - 1][v];
			up[i][v] = up[i - 1][mid];
			maxCostUp[i][v] = Math.max(maxCostUp[i - 1][v],
					maxCostUp[i - 1][mid]);
		}
		tIn[v] = time++;

		for (int idx = head[v]; idx >= 0; idx = next[idx]) {
			Edge e = to[idx];
			int u = e.v ^ e.u ^ v;
			if (u == p) {
				continue;
			}
			depth[u] = depth[v] + 1;
			dfs1(u, v, e.cost);
		}
		tOut[v] = time;
	}

	int get(int v) {
		return p[v] == v ? v : (p[v] = get(p[v]));
	}

	boolean unite(int v, int u) {
		v = get(v);
		u = get(u);
		if (v == u) {
			return false;
		}

		if (rng.nextBoolean()) {
			p[v] = u;
		} else {
			p[u] = v;
		}
		return true;
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {
		int n = 4;
		int m = 6;
		out.println(n + " " + m);
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				out.println(i + " " + j + " " + rand(1, 5));
			}
		}
	}

	D() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		 submit();
		// stress();
//		test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new D();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


import java.io.*;
import java.util.*;

public class D {

	static class Edge implements Comparable<Edge> {
		int v, u, cost, idx;

		public Edge(int v, int u, int cost, int idx) {
			this.v = v;
			this.u = u;
			this.cost = cost;
			this.idx = idx;
		}

		@Override
		public int compareTo(Edge o) {
			return Integer.compare(cost, o.cost);
		}
	}

	int[] head;
	int[] next;
	Edge[] to;

	void addEdge(Edge e, int pos) {
		to[2 * pos] = e;
		next[2 * pos] = head[e.v];
		head[e.v] = 2 * pos;

		to[2 * pos + 1] = e;
		next[2 * pos + 1] = head[e.u];
		head[e.u] = 2 * pos + 1;
	}

	int[] p;

	static final int INF = Integer.MAX_VALUE / 2;

	void submit() {
		int n = nextInt();
		int m = nextInt();

		Edge[] es = new Edge[m];

		for (int i = 0; i < m; i++) {
			int v = nextInt() - 1;
			int u = nextInt() - 1;
			int cost = nextInt();
			es[i] = new Edge(v, u, cost, i);
		}

		Arrays.sort(es);
		p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = i;
		}

		Arrays.sort(es);

		Edge[] mst = new Edge[n - 1];
		int ptr = 0;

		Edge[] nonMst = new Edge[m - n + 1];
		int ptrNonMst = 0;

		for (Edge e : es) {
			if (unite(e.v, e.u)) {
//				System.err.println(e.v + " " + e.u);
				mst[ptr++] = e;
			} else {
				nonMst[ptrNonMst++] = e;
			}
		}

		head = new int[n];
		Arrays.fill(head, -1);
		next = new int[2 * n - 2];
		to = new Edge[2 * n - 2];

		for (int i = 0; i < n - 1; i++) {
			addEdge(mst[i], i);
		}

		time = 0;
		depth = new int[n];
		tIn = new int[n];
		tOut = new int[n];
		up = new int[LOG][n];
		maxCostUp = new int[LOG][n];

		markMinUp = new int[LOG][n];
		for (int i = 0; i < LOG; i++) {
			Arrays.fill(markMinUp[i], INF);
		}

		dfs1(0, 0, -1);

		ans = new int[m];

		for (Edge e : nonMst) {
			int v = e.v;
			int u = e.u;
			int mid = lca(v, u);

			ans[e.idx] = Math.max(getAnsNoMst(v, mid, e.cost),
					getAnsNoMst(u, mid, e.cost)) - 1;
		}

		dfs2(0, 0, -1);

		for (int x : ans) {
			if(x == -1)
				out.println(1000*1000*1000);
			else out.println(x + 1);
			break;
		}
		// out.println();
	}

	void dfs2(int v, int p, int pEdge) {

		for (int idx = head[v]; idx >= 0; idx = next[idx]) {
			Edge e = to[idx];
			int u = e.v ^ e.u ^ v;
			if (u == p) {
				continue;
			}

			dfs2(u, v, e.idx);
		}

		if (pEdge == -1) {
			return;
		}

		int markSoFar = INF;

		for (int i = LOG - 1; i > 0; i--) {
			markSoFar = Math.min(markSoFar, markMinUp[i][v]);
			int mid = up[i - 1][v];
			markMinUp[i - 1][mid] = Math.min(markMinUp[i - 1][mid], markSoFar);
		}
		markSoFar = Math.min(markSoFar, markMinUp[0][v]);
		ans[pEdge] = markSoFar == INF ? -1 : markSoFar - 1;
	}

	int[] ans;

	int getAnsNoMst(int v, int u, int mark) {
		int ret = -1;
		for (int i = LOG - 1; i >= 0; i--) {
			int to = up[i][v];
			if (isAnc(u, to)) {
				ret = Math.max(ret, maxCostUp[i][v]);

				markMinUp[i][v] = Math.min(markMinUp[i][v], mark);
				v = to;
			}
		}
		return ret;
	}

	static final int LOG = 18;

	int[] tIn, tOut;
	int time;
	int[][] up;
	int[][] maxCostUp;
	int[] depth;
	int[][] markMinUp;

	boolean isAnc(int v, int u) {
		return tIn[v] <= tIn[u] && tOut[u] <= tOut[v];
	}

	int lca(int v, int u) {
		if (isAnc(v, u)) {
			return v;
		}
		if (isAnc(u, v)) {
			return u;
		}
		for (int i = LOG - 1; i >= 0; i--) {
			int to = up[i][v];
			if (!isAnc(to, u)) {
				v = to;
			}
		}
		return up[0][v];
	}

	void dfs1(int v, int p, int costUp) {
		up[0][v] = p;
		maxCostUp[0][v] = costUp;
		for (int i = 1; i < LOG; i++) {
			int mid = up[i - 1][v];
			up[i][v] = up[i - 1][mid];
			maxCostUp[i][v] = Math.max(maxCostUp[i - 1][v],
					maxCostUp[i - 1][mid]);
		}
		tIn[v] = time++;

		for (int idx = head[v]; idx >= 0; idx = next[idx]) {
			Edge e = to[idx];
			int u = e.v ^ e.u ^ v;
			if (u == p) {
				continue;
			}
			depth[u] = depth[v] + 1;
			dfs1(u, v, e.cost);
		}
		tOut[v] = time;
	}

	int get(int v) {
		return p[v] == v ? v : (p[v] = get(p[v]));
	}

	boolean unite(int v, int u) {
		v = get(v);
		u = get(u);
		if (v == u) {
			return false;
		}

		if (rng.nextBoolean()) {
			p[v] = u;
		} else {
			p[u] = v;
		}
		return true;
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {
		int n = 4;
		int m = 6;
		out.println(n + " " + m);
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				out.println(i + " " + j + " " + rand(1, 5));
			}
		}
	}

	D() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		 submit();
		// stress();
//		test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new D();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        static int n;
        static int m;
        static E1DaleksInvasionEasy.Subset[] subsets;

        private static int find(int i) {
            if (subsets[i].parent != i)
                subsets[i].parent = find(subsets[i].parent);
            return subsets[i].parent;
        }

        private static void union(int x, int y) {
            int xroot = find(x);
            int yroot = find(y);

            if (subsets[xroot].rank < subsets[yroot].rank)
                subsets[xroot].parent = yroot;
            else if (subsets[yroot].rank < subsets[xroot].rank)
                subsets[yroot].parent = xroot;
            else {
                subsets[xroot].parent = yroot;
                subsets[yroot].rank++;
            }
        }

        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            n = sc.nextInt();
            m = sc.nextInt();
            subsets = new E1DaleksInvasionEasy.Subset[n];
            for (int i = 0; i < n; i++) {
                subsets[i] = new E1DaleksInvasionEasy.Subset();
                subsets[i].parent = i;
                subsets[i].rank = 0;
            }

            E1DaleksInvasionEasy.Edges[] edges = new E1DaleksInvasionEasy.Edges[m];
            int x, y;
            long w;
            for (int i = 0; i < m; i++) {
                x = sc.nextInt() - 1;
                y = sc.nextInt() - 1;
                w = sc.nextLong();
                edges[i] = new E1DaleksInvasionEasy.Edges();
                edges[i].u = x;
                edges[i].v = y;
                edges[i].w = w;
                edges[i].idx = i;
            }
            E1DaleksInvasionEasy.Edges first = edges[0];
            int firstidx = edges[0].idx;
            int ans = -1;
            int l = 0, r = (int) 1e9;
            boolean tru;
            while (r - l >= 0) {
                for (int i = 0; i < n; i++) {
                    subsets[i].parent = i;
                    subsets[i].rank = 0;
                }
                tru = false;
                first.w = (r + l) / 2;
                Arrays.sort(edges, new Comparator<E1DaleksInvasionEasy.Edges>() {

                    public int compare(E1DaleksInvasionEasy.Edges a, E1DaleksInvasionEasy.Edges b) {
                        if (a.w == b.w) {
                            if (a.idx == firstidx) {
                                return -1;
                            }
                            if (b.idx == firstidx) {
                                return 1;
                            }
                            return 0;
                        }
                        return Long.compare(a.w, b.w);
                    }
                });
                for (E1DaleksInvasionEasy.Edges a : edges) {
                    if (find(a.u) != find(a.v)) {
                        union(a.u, a.v);
                        if (a.idx == firstidx) {
                            tru = true;
                        }
                    }
                }
                if (tru) {
                    ans = (r + l) / 2;
                    l = (r + l) / 2 + 1;
                } else {
                    r = (r + l) / 2 - 1;
                }
            }
            out.println(ans);
        }

        static class Edges {
            int u;
            int v;
            int idx;
            long w;

        }

        static class Subset {
            int parent;
            int rank;

        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        static int n;
        static int m;
        static E1DaleksInvasionEasy.Subset[] subsets;

        private static int find(int i) {
            if (subsets[i].parent != i)
                subsets[i].parent = find(subsets[i].parent);
            return subsets[i].parent;
        }

        private static void union(int x, int y) {
            int xroot = find(x);
            int yroot = find(y);

            if (subsets[xroot].rank < subsets[yroot].rank)
                subsets[xroot].parent = yroot;
            else if (subsets[yroot].rank < subsets[xroot].rank)
                subsets[yroot].parent = xroot;
            else {
                subsets[xroot].parent = yroot;
                subsets[yroot].rank++;
            }
        }

        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            n = sc.nextInt();
            m = sc.nextInt();
            subsets = new E1DaleksInvasionEasy.Subset[n];
            for (int i = 0; i < n; i++) {
                subsets[i] = new E1DaleksInvasionEasy.Subset();
                subsets[i].parent = i;
                subsets[i].rank = 0;
            }

            E1DaleksInvasionEasy.Edges[] edges = new E1DaleksInvasionEasy.Edges[m];
            int x, y;
            long w;
            for (int i = 0; i < m; i++) {
                x = sc.nextInt() - 1;
                y = sc.nextInt() - 1;
                w = sc.nextLong();
                edges[i] = new E1DaleksInvasionEasy.Edges();
                edges[i].u = x;
                edges[i].v = y;
                edges[i].w = w;
                edges[i].idx = i;
            }
            E1DaleksInvasionEasy.Edges first = edges[0];
            int firstidx = edges[0].idx;
            int ans = -1;
            int l = 0, r = (int) 1e9;
            boolean tru;
            while (r - l >= 0) {
                for (int i = 0; i < n; i++) {
                    subsets[i].parent = i;
                    subsets[i].rank = 0;
                }
                tru = false;
                first.w = (r + l) / 2;
                Arrays.sort(edges, Comparator.comparingLong(a -> a.w));
                for (E1DaleksInvasionEasy.Edges a : edges) {
                    if (find(a.u) != find(a.v)) {
                        union(a.u, a.v);
                        if (a.idx == firstidx) {
                            tru = true;
                        }
                    }
                }
                if (tru) {
                    ans = (r + l) / 2;
                    l = (r + l) / 2 + 1;
                } else {
                    r = (r + l) / 2 - 1;
                }
            }
            out.println(ans);
        }

        static class Edges {
            int u;
            int v;
            int idx;
            long w;

        }

        static class Subset {
            int parent;
            int rank;

        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author beginner1010
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE1 solver = new TaskE1();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE1 {
        int[] height;
        int[] parent;
        int[] preParent;
        int[] preHeight;

        int find(int node) {
            return node == parent[node] ? node : find(parent[node]);
        }

        void join(int a, int b) {
            a = find(a);
            b = find(b);
            if (a == b) {
                return;
            }
            preHeight[a] = height[a];
            preHeight[b] = height[b];
            preParent[a] = parent[a];
            preParent[b] = parent[b];
            if (height[a] > height[b]) {
                parent[b] = a;
            } else {
                parent[a] = b;
                if (height[a] == height[b]) height[b]++;
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[][] edges = new int[m][3];

            height = new int[n];
            parent = new int[n];
            preHeight = new int[n];
            preParent = new int[n];
            for (int i = 0; i < n; i++) {
                parent[i] = i;
            }
            for (int i = 0; i < m; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                int c = in.nextInt();
                edges[i] = new int[]{a, b, c};
            }

            int u = edges[0][0];
            int v = edges[0][1];

            Arrays.sort(edges, new Comparator<int[]>() {

                public int compare(int[] o1, int[] o2) {
                    if (o1[2] != o2[2]) return o1[2] < o2[2] ? -1 : 1;
                    if (o1[1] != o2[1]) return o1[1] < o2[1] ? -1 : 1;
                    if (o1[0] != o2[0]) return o1[0] < o2[0] ? -1 : 1;
                    return 0;
                }
            });

            int ans = (int) 1e+9;
            for (int i = 0; i < m; i++) {
                int a = edges[i][0];
                int b = edges[i][1];
                if (a == u && b == v)
                    continue;
                join(a, b);
                if (find(u) == find(v)) {
                    ans = edges[i][2];
                    break;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sgn;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jeel Vaishnav
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        int[] par;
        Edge[] e;

        boolean union(int i, int j) {
            i = findSet(i);
            j = findSet(j);

            if (i == j)
                return false;

            par[j] = i;
            return true;
        }

        int findSet(int i) {
            if (par[i] == i)
                return i;
            par[i] = findSet(par[i]);
            return par[i];
        }

        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            int n = sc.nextInt();
            int m = sc.nextInt();

            e = new Edge[m];
            for (int i = 0; i < m; ++i) {
                e[i] = new Edge(i, sc.nextInt() - 1, sc.nextInt() - 1, sc.nextLong());
            }

            par = new int[n];
            long start = 0, end = (long) 1e9, ans = 0;
            while (start <= end) {
                long mid = (start + end) >> 1;

                for (int i = 0; i < m; ++i) {
                    if (e[i].ind == 0)
                        e[i].weight = mid;
                }

                Arrays.sort(e, new Comparator<Edge>() {

                    public int compare(Edge o1, Edge o2) {
                        if (o1.weight < o2.weight)
                            return -1;
                        if (o1.weight > o2.weight)
                            return 1;

                        if (o1.ind < o2.ind)
                            return -1;
                        if (o1.ind > o2.ind)
                            return 1;
                        return 0;
                    }
                });

                for (int i = 0; i < n; ++i)
                    par[i] = i;

                int flag = 0;
                for (int i = 0; i < m; ++i) {
                    if (union(e[i].u, e[i].v)) {
                        if (e[i].ind == 0)
                            flag = 1;
                    }
                }

                if (flag == 1) {
                    ans = mid;
                    start = mid + 1;
                } else
                    end = mid - 1;
            }

            out.print(ans);
        }

        class Edge {
            int u;
            int v;
            int ind;
            long weight;

            Edge(int a, int b, int c, long d) {
                ind = a;
                u = b;
                v = c;
                weight = d;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.util.*;
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;

public class Main {
    public boolean help(ArrayList<edge> list,int m,int xx,int yy) {
        dsu tree=new dsu(m);
        int flag=0;
        Collections.sort(list,new a(xx,yy));
        for(edge e:list) {
            if(tree.find(e.a)!=tree.find(e.b)) {
                tree.union(e.a, e.b);
                if(e.a==xx && e.b==yy) {
                    flag=1;
                    break;
                }
                if(e.b==xx && e.a==yy) {
                    flag=1;
                    break;
                }
            }
        }
        if(flag==1) {
            return true;
        }
        else {
            return false;
        }
    }
    public static void main(String[] args) throws Exception{
        FastReader sc=new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Main mm=new Main();
        int n=sc.nextInt();
        int m=sc.nextInt();
        ArrayList<edge> list=new ArrayList<edge>();
        int flag=0;
        int xx=-1;int yy=-1;
        int value;
        for(int i=0;i<m;i++) {
            int x=sc.nextInt()-1;
            int y=sc.nextInt()-1;
            value=sc.nextInt();
            if(x>y) {
                int temp=x;
                x=y;
                y=temp;
            }
            if(flag==0) {
                xx=x;yy=y;flag=1;
            }
            else {
            list.add(new edge(x,y,value));
            }
        }
        int l=1;
        int r=1000000000;
        int ans=-1;
        while(l<=r) {
            int mid=(l+r)/2;
            list.add(new edge(xx,yy,mid));
            boolean temp=mm.help(list, n,xx,yy);
            int ind=-1;
            for(int i=0;i<m;i++) {
                if(list.get(i).a==xx && list.get(i).b==yy) {
                    ind=i;
                    break;
                }
            }
            list.remove(ind);
            if(temp) {
                ans=mid;
                l=mid+1;
            }
            else {
                r=mid-1;
            }
        }
        System.out.println(ans);
    }
}
class edge{
    int a;
    int b;
    int value;
    edge(int a,int b,int value){
        this.a=a;
        this.b=b;
        this.value=value;
    }
}
class a implements Comparator<edge>{
    int x;int y;
    a(int x,int y){
        this.x=x;
        this.y=y;
    }
    public int compare(edge e1,edge e2) {
        if(e1.value==e2.value) {
            if(e1.a==x && e1.b==y) {
                return -1;
            }
            else if(e2.a==x && e2.b==y) {
                return 1;
            }
        }
        return e1.value-e2.value;
    }
}
class dsu{
    int[] parent;
    int[] rank;
    dsu(int a){
        parent=new int[a];
        rank=new int[a];
        for(int i=0;i<a;i++) {
            parent[i]=i;
            rank[i]=0;
        }
    }
    public int find(int a) {
        int temp=a+0;
        while(parent[temp]!=temp) {
            temp=parent[temp];
        }
        parent[a]=temp;
        return temp;
    }
    public boolean istrue(int a,int b){
        if(find(a)!=find(b)) {
            return false;
        }

    else {
        return true;
    }
    }
    public void union(int a,int b) {
        int x=find(a);
        int y=find(b);
        if(x!=y) {
            if(rank[x]==rank[y]) {
                parent[x]=y;
                rank[y]+=1;
            }
            else if(rank[x]>rank[y]) {
                parent[y]=x;
            }
            else {
                parent[x]=y;
            }
        }
    }
}
class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader()
    {
        br = new BufferedReader(new
                 InputStreamReader(System.in));
    }

    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;

public class Main {
    public boolean help(ArrayList<edge> list,int m,int xx,int yy) {
        dsu tree=new dsu(m);
        int flag=0;
        Collections.sort(list,new a(xx,yy));
        for(edge e:list) {
            if(tree.find(e.a)!=tree.find(e.b)) {
                tree.union(e.a, e.b);
                if(e.a==xx && e.b==yy) {
                    flag=1;
                    break;
                }
                if(e.b==xx && e.a==yy) {
                    flag=1;
                    break;
                }
            }
        }
        if(flag==1) {
            return true;
        }
        else {
            return false;
        }
    }
    public static void main(String[] args) throws Exception{
        FastReader sc=new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Main mm=new Main();
        int n=sc.nextInt();
        int m=sc.nextInt();
        ArrayList<edge> list=new ArrayList<edge>();
        int flag=0;
        int xx=-1;int yy=-1;
        int value;
        for(int i=0;i<m;i++) {
            int x=sc.nextInt()-1;
            int y=sc.nextInt()-1;
            value=sc.nextInt();
            if(x>y) {
                int temp=x;
                x=y;
                y=temp;
            }
            if(flag==0) {
                xx=x;yy=y;flag=1;
            }
            else {
            list.add(new edge(x,y,value));
            }
        }
        int l=1;
        int r=1000000000;
        int ans=-1;
        while(l<=r) {
            int mid=(l+r)/2;
            list.add(new edge(xx,yy,mid));
            boolean temp=mm.help(list, m,xx,yy);
            int ind=-1;
            for(int i=0;i<m;i++) {
                if(list.get(i).a==xx && list.get(i).b==yy) {
                    ind=i;
                    break;
                }
            }
            list.remove(ind);
            if(temp) {
                ans=mid;
                l=mid+1;
            }
            else {
                r=mid-1;
            }
        }
        System.out.println(ans);
    }
}
class edge{
    int a;
    int b;
    int value;
    edge(int a,int b,int value){
        this.a=a;
        this.b=b;
        this.value=value;
    }
}
class a implements Comparator<edge>{
    int x;int y;
    a(int x,int y){
        this.x=x;
        this.y=y;
    }
    public int compare(edge e1,edge e2) {
        if(e1.value==e2.value) {
            if(e1.a==x && e1.b==y) {
                return -1;
            }
            else if(e2.a==x && e2.b==y) {
                return 1;
            }
        }
        return e1.value-e2.value;
    }
}
class dsu{
    int[] parent;
    int[] rank;
    dsu(int a){
        parent=new int[a];
        rank=new int[a];
        for(int i=0;i<a;i++) {
            parent[i]=i;
            rank[i]=0;
        }
    }
    public int find(int a) {
        int temp=a+0;
        while(parent[temp]!=temp) {
            temp=parent[temp];
        }
        parent[a]=temp;
        return temp;
    }
    public boolean istrue(int a,int b){
        if(find(a)!=find(b)) {
            return false;
        }

    else {
        return true;
    }
    }
    public void union(int a,int b) {
        int x=find(a);
        int y=find(b);
        if(x!=y) {
            if(rank[x]==rank[y]) {
                parent[x]=y;
                rank[y]+=1;
            }
            else if(rank[x]>rank[y]) {
                parent[y]=x;
            }
            else {
                parent[x]=y;
            }
        }
    }
}
class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader()
    {
        br = new BufferedReader(new
                 InputStreamReader(System.in));
    }

    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;

public class Main {
    public boolean help(ArrayList<edge> list,int m,int xx,int yy) {
        dsu tree=new dsu(m);
        int flag=0;
        Collections.sort(list,new a(xx,yy));
        for(edge e:list) {
            if(tree.find(e.a)!=tree.find(e.b)) {
                tree.union(e.a, e.b);
                if(e.a==xx && e.b==yy) {
                    flag=1;
                    break;
                }
                if(e.b==xx && e.a==yy) {
                    flag=1;
                    break;
                }
            }
        }
        if(flag==1) {
            return true;
        }
        else {
            return false;
        }
    }
    public static void main(String[] args) throws Exception{
        FastReader sc=new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Main mm=new Main();
        int n=sc.nextInt();
        int m=sc.nextInt();
        ArrayList<edge> list=new ArrayList<edge>();
        int flag=0;
        int xx=-1;int yy=-1;
        int value;
        for(int i=0;i<m;i++) {
            int x=sc.nextInt()-1;
            int y=sc.nextInt()-1;
            value=sc.nextInt();
            if(x>y) {
                int temp=x;
                x=y;
                y=temp;
            }
            if(flag==0) {
                xx=x;yy=y;flag=1;
            }
            else {
            list.add(new edge(x,y,value));
            }
        }
        int l=1;
        int r=1000000000;
        int ans=-1;
        while(l<=r) {
            int mid=(l+r)/2;
            list.add(new edge(xx,yy,mid));
            boolean temp=mm.help(list, m,xx,yy);
            for(int i=0;i<m;i++) {
                if(list.get(i).a==xx && list.get(i).b==yy) {
                    list.remove(i);
                    break;
                }
            }
            if(temp) {
                ans=mid;
                l=mid+1;
            }
            else {
                r=mid-1;
            }
        }
        System.out.println(ans);
    }
}
class edge{
    int a;
    int b;
    int value;
    edge(int a,int b,int value){
        this.a=a;
        this.b=b;
        this.value=value;
    }
}
class a implements Comparator<edge>{
    int x;int y;
    a(int x,int y){
        this.x=x;
        this.y=y;
    }
    public int compare(edge e1,edge e2) {
        if(e1.value==e2.value) {
            if(e1.a==x && e1.b==y) {
                return -1;
            }
            else if(e2.a==x && e2.b==y) {
                return 1;
            }
        }
        return e1.value-e2.value;
    }
}
class dsu{
    int[] parent;
    int[] rank;
    dsu(int a){
        parent=new int[a];
        rank=new int[a];
        for(int i=0;i<a;i++) {
            parent[i]=i;
            rank[i]=0;
        }
    }
    public int find(int a) {
        int temp=a+0;
        while(parent[temp]!=temp) {
            temp=parent[temp];
        }
        parent[a]=temp;
        return temp;
    }
    public boolean istrue(int a,int b){
        if(find(a)!=find(b)) {
            return false;
        }

    else {
        return true;
    }
    }
    public void union(int a,int b) {
        int x=find(a);
        int y=find(b);
        if(x!=y) {
            if(rank[x]==rank[y]) {
                parent[x]=y;
                rank[y]+=1;
            }
            else if(rank[x]>rank[y]) {
                parent[y]=x;
            }
            else {
                parent[x]=y;
            }
        }
    }
}
class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader()
    {
        br = new BufferedReader(new
                 InputStreamReader(System.in));
    }

    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;

public class Main {
    public boolean help(ArrayList<edge> list,int m,int xx,int yy) {
        dsu tree=new dsu(m);
        int flag=0;
        Collections.sort(list,new a(xx,yy));
        for(edge e:list) {
            if(tree.find(e.a)!=tree.find(e.b)) {
                tree.union(e.a, e.b);
                if(e.a==xx && e.b==yy) {
                    flag=1;
                    break;
                }
                if(e.b==xx && e.a==yy) {
                    flag=1;
                    break;
                }
            }
        }
        if(flag==1) {
            return true;
        }
        else {
            return false;
        }
    }
    public static void main(String[] args) throws Exception{
        FastReader sc=new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Main mm=new Main();
        int n=sc.nextInt();
        int m=sc.nextInt();
        ArrayList<edge> list=new ArrayList<edge>();
        int flag=0;
        int xx=-1;int yy=-1;
        int value;
        for(int i=0;i<m;i++) {
            int x=sc.nextInt()-1;
            int y=sc.nextInt()-1;
            value=sc.nextInt();
            if(x>y) {
                int temp=x;
                x=y;
                y=temp;
            }
            if(flag==0) {
                xx=x;yy=y;flag=1;
            }
            else {
            list.add(new edge(x,y,value));
            }
        }
        int l=0;
        int r=1000000000;
        int ans=-1;
        while(l<=r) {
            int mid=(l+r)/2;
            list.add(new edge(xx,yy,mid));
            boolean temp=mm.help(list, n,xx,yy);
            int ind=-1;
            for(int i=0;i<m;i++) {
                if(list.get(i).a==xx && list.get(i).b==yy) {
                    ind=i;
                    break;
                }
            }
            list.remove(ind);
            if(temp) {
                ans=mid;
                l=mid+1;
            }
            else {
                r=mid-1;
            }
        }
        System.out.println(ans);
    }
}
class edge{
    int a;
    int b;
    int value;
    edge(int a,int b,int value){
        this.a=a;
        this.b=b;
        this.value=value;
    }
}
class a implements Comparator<edge>{
    int x;int y;
    a(int x,int y){
        this.x=x;
        this.y=y;
    }
    public int compare(edge e1,edge e2) {
        if(e1.value==e2.value) {
            if(e1.a==x && e1.b==y) {
                return -1;
            }
            else if(e2.a==x && e2.b==y) {
                return 1;
            }
        }
        return e1.value-e2.value;
    }
}
class dsu{
    int[] parent;
    int[] rank;
    dsu(int a){
        parent=new int[a];
        rank=new int[a];
        for(int i=0;i<a;i++) {
            parent[i]=i;
            rank[i]=0;
        }
    }
    public int find(int a) {
        int temp=a+0;
        while(parent[temp]!=temp) {
            temp=parent[temp];
        }
        parent[a]=temp;
        return temp;
    }
    public boolean istrue(int a,int b){
        if(find(a)!=find(b)) {
            return false;
        }

    else {
        return true;
    }
    }
    public void union(int a,int b) {
        int x=find(a);
        int y=find(b);
        if(x!=y) {
            if(rank[x]==rank[y]) {
                parent[x]=y;
                rank[y]+=1;
            }
            else if(rank[x]>rank[y]) {
                parent[y]=x;
            }
            else {
                parent[x]=y;
            }
        }
    }
}
class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader()
    {
        br = new BufferedReader(new
                 InputStreamReader(System.in));
    }

    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class q5 {

	public static void main(String[] args) throws IOException {

	Reader.init(System.in);
	PrintWriter out=new PrintWriter(System.out);
	int n=Reader.nextInt();
	int m=Reader.nextInt();
	int[] included=new int[m];
	NoD[] arr=new NoD[m];
	NoD[] arr2=new NoD[m];
	for(int i=0;i<m;i++) {
		NoD c=new NoD(Reader.nextInt(),Reader.nextInt(),Reader.nextInt(),i);
		arr[i]=c;
		arr2[i]=c;
	}

	int low=0,high=(int)1e9;
	int ans=0;
	while(low<=high) {
		int mid=(low+high)/2;
		arr2[0].z=mid;
		Arrays.sort(arr,new Comparator<NoD>() {
			public int compare(NoD a,NoD b) {
				if(a.z==b.z) {
					return (int)( Math.abs(a.x-arr2[0].x)+Math.abs(a.y-arr2[0].y));
				}
				return a.z-b.z;
			}
		});
		DisJoint set=new DisJoint(n);
		for(NoD c:arr) {
			if(set.find(c.x)!=set.find(c.y)) {
				set.union(c.x, c.y);
				included[c.i]=mid;
			}
		}
		if(included[0]==mid) {
			low=mid+1;
			ans=mid;
		}
		else high=mid-1;
	}
	out.println(ans);

	out.flush();

	}
}

class NoD{
	int x,y,z,i;
	NoD(int a,int b,int c,int d){
		x=a;y=b;z=c;i=d;
	}
}

class DisJoint {
	int[] arr;
	int[] parent;
	int[] rank;
	DisJoint(int n){
		arr=new int[n+1];
		parent=new int[n+1];
		rank=new int[n+1];
		for(int i=1;i<=n;i++) {
			arr[i]=i;
			parent[i]=i;
			rank[i]=0;
		}
	}

	int find(int value) {
		int par=parent[value];
		if(par==value)
			return par;
		parent[value]=find(par);
		return parent[value];
	}

	void union(int data1,int data2) {
		int parent1=find(data1);
		int parent2=find(data2);
		if(parent1!=parent2) {
			if(rank[parent1]>=rank[parent2]) {
				parent[parent2]=parent1;
				if(rank[parent1]==rank[parent2])
					rank[parent1]++;
			}
			else {
				parent[parent1]=parent2;
			}
		}

	}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */
    static void init() throws IOException {
    	 reader = new BufferedReader(
                 new FileReader("pattern.in") );
    tokenizer = new StringTokenizer("");
    }
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class q5 {

	public static void main(String[] args) throws IOException {

	Reader.init(System.in);
	PrintWriter out=new PrintWriter(System.out);
	int n=Reader.nextInt();
	int m=Reader.nextInt();
	int[] included=new int[m];
	NoD[] arr=new NoD[m];
	NoD[] arr2=new NoD[m];
	for(int i=0;i<m;i++) {
		NoD c=new NoD(Reader.nextInt(),Reader.nextInt(),Reader.nextInt(),i);
		arr[i]=c;
		arr2[i]=c;
	}

	int low=0,high=(int)1e9;
	int ans=0;
	while(low<=high) {
		int mid=(low+high)/2;
		arr2[0].z=mid;
		Arrays.sort(arr,new Comparator<NoD>() {
			public int compare(NoD a,NoD b) {
				if(a.z==b.z) return a.i-b.i;
				return a.z-b.z;
			}
		});
		int l=0,h=m-1;
		int p=-1;
		while(l<=h) {
			int mi=(l+h)/2;
			if(arr[mi].z==mid) {
				p=mi;h=mi-1;
			}
			else if(arr[mi].z<mid) {
				l=mi+1;
			}
			else {
				h=mi-1;
			}
		}
		NoD cc=arr[p];

		DisJoint set=new DisJoint(n);
		for(NoD c:arr) {
			if(set.find(c.x)!=set.find(c.y)) {
				set.union(c.x, c.y);
				included[c.i]=mid;
			}
		}
		if(included[0]==mid) {
			low=mid+1;
			ans=mid;
		}
		else high=mid-1;
	}
	out.println(ans);

	out.flush();

	}
}

class NoD{
	int x,y,z,i;
	NoD(int a,int b,int c,int d){
		x=a;y=b;z=c;i=d;
	}
}

class DisJoint {
	int[] arr;
	int[] parent;
	int[] rank;
	DisJoint(int n){
		arr=new int[n+1];
		parent=new int[n+1];
		rank=new int[n+1];
		for(int i=1;i<=n;i++) {
			arr[i]=i;
			parent[i]=i;
			rank[i]=0;
		}
	}

	int find(int value) {
		int par=parent[value];
		if(par==value)
			return par;
		parent[value]=find(par);
		return parent[value];
	}

	void union(int data1,int data2) {
		int parent1=find(data1);
		int parent2=find(data2);
		if(parent1!=parent2) {
			if(rank[parent1]>=rank[parent2]) {
				parent[parent2]=parent1;
				if(rank[parent1]==rank[parent2])
					rank[parent1]++;
			}
			else {
				parent[parent1]=parent2;
			}
		}

	}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */
    static void init() throws IOException {
    	 reader = new BufferedReader(
                 new FileReader("pattern.in") );
    tokenizer = new StringTokenizer("");
    }
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.IOException;
import java.util.TreeSet;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aman Kumar Singh
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        PrintWriter out;
        InputReader in;
        int n;
        final Comparator<Pair> com = new Comparator<Pair>() {
            public int compare(Pair a, Pair b) {
                if (Integer.compare(a.x, b.x) != 0)
                    return Integer.compare(a.x, b.x);
                else
                    return Integer.compare(a.y, b.y);
            }
        };

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int m = ni();
            int[][] edges = new int[m][2];
            DSU ob = new DSU(n);
            Pair[] hola = new Pair[m];
            int i = 0;
            int[][] store = new int[m][3];
            int x = -1, y = -1;
            for (i = 0; i < m; i++) {
                int u = ni() - 1;
                int v = ni() - 1;
                store[i][0] = u;
                store[i][1] = v;
                store[i][2] = ni();
                hola[i] = new Pair(store[i][2], i);
            }
            Arrays.sort(hola, com);
            long wt = 0;
            boolean[] taken = new boolean[m];
            for (i = 0; i < m; i++) {
                if (hola[i].y == 0)
                    continue;
                int u = store[hola[i].y][0];
                int v = store[hola[i].y][1];
                long w = hola[i].x;
                if (ob.find(u) != ob.find(v)) {
                    ob.unite(u, v);
                    Edge e = new Edge(u, v, w);
                    wt = Math.max(w, wt);
                }
            }
            int haha = (int) 1e9;
            if (m == n - 1)
                pn(haha);
            else {
                ob = new DSU(n);
                int mn = (int) 1e9;
                taken = new boolean[m];
                int mx = 0;
                for (i = 0; i < m; i++) {
                    int u = store[hola[i].y][0];
                    int v = store[hola[i].y][1];
                    long w = hola[i].x;
                    if (ob.find(u) != ob.find(v)) {
                        ob.unite(u, v);
                        taken[hola[i].y] = true;
                    } else {
                        mn = Math.min(mn, store[hola[i].y][2]);

                    }
                    mx = Math.max(mx, store[hola[i].y][2]);
                }
                TreeSet<Integer> ar = new TreeSet<>();
                ar.add(mn);
                ar.add(mx);
                ar.add((int) wt);
                ar.add(store[0][2]);
                ar.add((int) 1e9);
                int ans = 0;
                for (int xx : ar) {
                    PriorityQueue<Pair> pq = new PriorityQueue<>(com);
                    pq.add(new Pair(xx, 0));
                    for (i = 1; i < m; i++)
                        pq.add(new Pair(store[i][2], i));
                    ob.clear(n);
                    boolean ok = false;
                    while (pq.size() > 0) {
                        Pair yo = pq.poll();
                        int u = store[yo.y][0];
                        int v = store[yo.y][1];
                        long w = yo.x;
                        if (ob.find(u) != ob.find(v)) {
                            ob.unite(u, v);
                            if (yo.y == 0) {
                                ok = true;
                                break;
                            }
                        }
                    }
                    if (ok)
                        ans = Math.max(ans, xx);
                }
                pn(Math.min(ans, (int) 1e9));
            }
        }

        int ni() {
            return in.nextInt();
        }

        void pn(Object o) {
            out.println(o);
        }

        class DSU {
            int[] rank;
            int[] parent;

            public DSU(int n) {
                rank = new int[n];
                parent = new int[n];
                make_set(n);
            }

            void clear(int n) {
                make_set(n);
                Arrays.fill(rank, 0);
            }

            void make_set(int n) {
                int i = 0;
                for (i = 0; i < n; i++)
                    parent[i] = i;
            }

            int find(int x) {
                if (parent[x] != x)
                    parent[x] = find(parent[x]);
                return parent[x];
            }

            void unite(int x, int y) {
                int xRoot = find(x), yRoot = find(y);
                if (xRoot == yRoot)
                    return;
                if (rank[xRoot] < rank[yRoot])
                    parent[xRoot] = yRoot;
                else if (rank[yRoot] < rank[xRoot])
                    parent[yRoot] = xRoot;
                else {
                    parent[yRoot] = xRoot;
                    rank[xRoot] = rank[xRoot] + 1;
                }
            }

        }

        class Pair {
            int x;
            int y;

            Pair(int p, int q) {
                x = p;
                y = q;
            }

        }

        class Edge {
            int u;
            int v;
            long wt;

            Edge(int a, int b, long w) {
                u = a;
                v = b;
                wt = w;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aman Kumar Singh
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        PrintWriter out;
        InputReader in;
        int n;
        final Comparator<Pair> com = new Comparator<Pair>() {
            public int compare(Pair a, Pair b) {
                if (Integer.compare(a.x, b.x) != 0)
                    return Integer.compare(a.x, b.x);
                else
                    return Integer.compare(a.y, b.y);
            }
        };

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int m = ni();
            int[][] edges = new int[m][2];
            DSU ob = new DSU(n);
            Pair[] hola = new Pair[m];
            int i = 0;
            int[][] store = new int[m][3];
            int x = -1, y = -1;
            for (i = 0; i < m; i++) {
                int u = ni() - 1;
                int v = ni() - 1;
                store[i][0] = u;
                store[i][1] = v;
                store[i][2] = ni();
                hola[i] = new Pair(store[i][2], i);
            }
            Arrays.sort(hola, com);
            long wt = 0;
            boolean[] taken = new boolean[m];
            for (i = 0; i < m; i++) {
                if (hola[i].y == 0)
                    continue;
                int u = store[hola[i].y][0];
                int v = store[hola[i].y][1];
                long w = hola[i].x;
                if (ob.find(u) != ob.find(v)) {
                    ob.unite(u, v);
                    Edge e = new Edge(u, v, w);
                    wt = Math.max(w, wt);
                }
            }
            int haha = (int) 1e9;
            if (m == n - 1)
                pn(haha);
            else {
                ob = new DSU(n);
                int mn = (int) 1e9;
                taken = new boolean[m];
                for (i = 0; i < m; i++) {
                    int u = store[hola[i].y][0];
                    int v = store[hola[i].y][1];
                    long w = hola[i].x;
                    if (ob.find(u) != ob.find(v)) {
                        ob.unite(u, v);
                        Edge e = new Edge(u, v, w);
                        taken[hola[i].y] = true;
                    } else
                        mn = Math.min(mn, store[hola[i].y][2]);
                }
                ArrayList<Integer> ar = new ArrayList<>();
                ar.add(mn);
                ar.add(mn + 1);
                ar.add((int) wt);
                ar.add((int) wt + 1);
                ar.add(store[0][2]);
                ar.add(store[0][2] + 1);
                ar.add((int) 1e9);
                int ans = 0;
                for (int xx : ar) {
                    PriorityQueue<Pair> pq = new PriorityQueue<>(com);
                    pq.add(new Pair(xx, 0));
                    for (i = 1; i < m; i++)
                        pq.add(new Pair(store[i][2], i));
                    ob.clear(n);
                    boolean ok = false;
                    while (pq.size() > 0) {
                        Pair yo = pq.poll();
                        int u = store[yo.y][0];
                        int v = store[yo.y][1];
                        long w = yo.x;
                        if (ob.find(u) != ob.find(v)) {
                            ob.unite(u, v);
                            if (yo.y == 0) {
                                ok = true;
                                break;
                            }
                        }
                    }
                    if (ok)
                        ans = Math.max(ans, xx);
                }
                pn(Math.min(ans, (int) 1e9));
            }
        }

        int ni() {
            return in.nextInt();
        }

        void pn(Object o) {
            out.println(o);
        }

        class DSU {
            int[] rank;
            int[] parent;

            public DSU(int n) {
                rank = new int[n];
                parent = new int[n];
                make_set(n);
            }

            void clear(int n) {
                make_set(n);
                Arrays.fill(rank, 0);
            }

            void make_set(int n) {
                int i = 0;
                for (i = 0; i < n; i++)
                    parent[i] = i;
            }

            int find(int x) {
                if (parent[x] != x)
                    parent[x] = find(parent[x]);
                return parent[x];
            }

            void unite(int x, int y) {
                int xRoot = find(x), yRoot = find(y);
                if (xRoot == yRoot)
                    return;
                if (rank[xRoot] < rank[yRoot])
                    parent[xRoot] = yRoot;
                else if (rank[yRoot] < rank[xRoot])
                    parent[yRoot] = xRoot;
                else {
                    parent[yRoot] = xRoot;
                    rank[xRoot] = rank[xRoot] + 1;
                }
            }

        }

        class Pair {
            int x;
            int y;

            Pair(int p, int q) {
                x = p;
                y = q;
            }

        }

        class Edge {
            int u;
            int v;
            long wt;

            Edge(int a, int b, long w) {
                u = a;
                v = b;
                wt = w;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aman Kumar Singh
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1DaleksInvasionEasy solver = new E1DaleksInvasionEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1DaleksInvasionEasy {
        PrintWriter out;
        InputReader in;
        int n;
        final Comparator<Pair> com = new Comparator<Pair>() {
            public int compare(Pair a, Pair b) {
                if (Integer.compare(a.x, b.x) != 0)
                    return Integer.compare(a.x, b.x);
                else
                    return Integer.compare(a.y, b.y);
            }
        };

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            int m = ni();
            int[][] edges = new int[m][2];
            DSU ob = new DSU(n);
            Pair[] hola = new Pair[m];
            int i = 0;
            int[][] store = new int[m][3];
            int x = -1, y = -1;
            for (i = 0; i < m; i++) {
                int u = ni() - 1;
                int v = ni() - 1;
                store[i][0] = u;
                store[i][1] = v;
                store[i][2] = ni();
                hola[i] = new Pair(store[i][2], i);
            }
            Arrays.sort(hola, com);
            long wt = 0;
            boolean[] taken = new boolean[m];
            for (i = 0; i < m; i++) {
                if (hola[i].y == 0)
                    continue;
                int u = store[hola[i].y][0];
                int v = store[hola[i].y][1];
                long w = hola[i].x;
                if (ob.find(u) != ob.find(v)) {
                    ob.unite(u, v);
                    Edge e = new Edge(u, v, w);
                    wt = Math.max(w, wt);
                    taken[hola[i].y] = true;
                }
            }
            int haha = (int) 1e9;
            if (m == n - 1)
                pn(haha);
            else if (wt < store[0][2])
                pn(wt);
            else {
                int mx = 0;
                for (i = 1; i < m; i++) {
                    if (!taken[i])
                        mx = Math.max(mx, store[i][2]);
                }
                pn(mx);
            }
        }

        int ni() {
            return in.nextInt();
        }

        void pn(Object o) {
            out.println(o);
        }

        class DSU {
            int[] rank;
            int[] parent;

            public DSU(int n) {
                rank = new int[n];
                parent = new int[n];
                make_set(n);
            }

            void make_set(int n) {
                int i = 0;
                for (i = 0; i < n; i++)
                    parent[i] = i;
            }

            int find(int x) {
                if (parent[x] != x)
                    parent[x] = find(parent[x]);
                return parent[x];
            }

            void unite(int x, int y) {
                int xRoot = find(x), yRoot = find(y);
                if (xRoot == yRoot)
                    return;
                if (rank[xRoot] < rank[yRoot])
                    parent[xRoot] = yRoot;
                else if (rank[yRoot] < rank[xRoot])
                    parent[yRoot] = xRoot;
                else {
                    parent[yRoot] = xRoot;
                    rank[xRoot] = rank[xRoot] + 1;
                }
            }

        }

        class Pair {
            int x;
            int y;

            Pair(int p, int q) {
                x = p;
                y = q;
            }

        }

        class Edge {
            int u;
            int v;
            long wt;

            Edge(int a, int b, long w) {
                u = a;
                v = b;
                wt = w;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}