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 if (wt <= store[0][2])
                pn(wt);
            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(ans);
            }
        }

        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;
        }

    }
}


//package math_codet;

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 lets_do {
    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 {
        long INF = (long) 1e18 + 1;
        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;
                if(i == 0) {
                	x = u;
                	y = v;
                }
                store[i][0] = u;
                store[i][1] = v;
                store[i][2] = ni();
                hola[i] = new Pair(store[i][2], i);
                if(i == 0)
                	hola[i] = new Pair((int)1e9 + 5, 1111111111);
            }
            Arrays.sort(hola, com);
            long wt = 0;
            int haha = (int) 1e9;
            if (m == n - 1)
                pn(haha);
            else {
                ob = new DSU(n);
                long mn = INF;
                for (i = 0; i < m - 1; i++) {
                    int u = store[hola[i].y][0];
                    int v = store[hola[i].y][1];
                    long w = hola[i].x;
                    ob.unite(u, v);
                    if(ob.find(x) == ob.find(y))
                        mn = Math.min(mn, store[hola[i].y][2]);
                }
                pn(mn);
            }
        }

        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;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.io.IOException;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.ArrayList;
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 i = 0;
            int[][] store = new int[m][3];
            int x = -1, y = -1;
            int haha = (int) 1e9;
            ArrayList<Integer> ar = new ArrayList<>();
            TreeSet<Integer> tset = new TreeSet<>();
            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();
                tset.add(store[i][2]);
            }
            tset.add(haha);
            for (int xx : tset)
                ar.add(xx);
            DSU ob = new DSU(n);

            int lo = 0, hi = ar.size() - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                PriorityQueue<Pair> pq = new PriorityQueue<>(com);
                pq.add(new Pair(ar.get(mid), 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 hola = pq.poll();
                    int u = store[hola.y][0];
                    int v = store[hola.y][1];
                    long w = hola.x;
                    if (ob.find(u) != ob.find(v)) {
                        ob.unite(u, v);
                        if (hola.y == 0) {
                            ok = true;
                            break;
                        }
                    }
                }
                if (ok)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            pn(ar.get(lo - 1));
        }

        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);
            }

            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;
            }

        }

    }

    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;
                if (i == 0) {
                    x = u;
                    y = v;
                }
                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;
            for (i = 0; i < m; i++) {
                int u = store[hola[i].y][0];
                int v = store[hola[i].y][1];
                if (u == x && v == y)
                    continue;
                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);
                }
            }
            if (m == n - 1 || wt > store[0][2]) {
                pn(store[0][2]);
            } else
                pn(wt);
        }

        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;
        }

    }
}


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.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;
            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);
                }
            }

            ob = new DSU(n);
            int mn = (int) 1e9;
            int mx = 0;
            ArrayList<Integer> ar1 = new ArrayList<>();
            for (i = 0; i < m; i++) {
                int u = store[hola[i].y][0];
                int v = store[hola[i].y][1];
                int w = hola[i].x;
                if (ob.find(u) != ob.find(v)) {
                    ob.unite(u, v);
                } else {
                    mn = Math.min(mn, w);
                    ar1.add(mn);
                }
                mx = Math.max(mx, w);
            }

            TreeSet<Integer> ar = new TreeSet<>();
            int cnt = 0;
            for (int xx : ar1) {
                if (xx > store[0][2]) {
                    ar.add(xx);
                    cnt++;
                }
            }
            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];
                    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.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;
            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);
                }
            }

            ob = new DSU(n);
            int mn = (int) 1e9;
            int mx = 0;
            for (i = 0; i < m; i++) {
                int u = store[hola[i].y][0];
                int v = store[hola[i].y][1];
                int w = hola[i].x;
                if (ob.find(u) != ob.find(v)) {
                    ob.unite(u, v);
                } else {
                    mn = Math.min(mn, w);
                }
                mx = Math.max(mx, w);
            }
            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];
                    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.TreeSet;
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;
            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);
                }
            }

            ob = new DSU(n);
            int mn = (int) 1e9;
            int mx = 0;
            ArrayList<Integer> ar1 = new ArrayList<>();
            for (i = 0; i < m; i++) {
                int u = store[hola[i].y][0];
                int v = store[hola[i].y][1];
                int w = hola[i].x;
                if (ob.find(u) != ob.find(v)) {
                    ob.unite(u, v);
                } else {
                    mn = Math.min(mn, w);
                    ar1.add(w);
                }

                mx = Math.max(mx, w);
            }

            TreeSet<Integer> ar = new TreeSet<>();
            int cnt = 0;
            for (int xx : ar1) {
                if (xx > store[0][2]) {
                    ar.add(xx);
                    cnt++;
                }
                if (cnt == 5)
                    break;
            }
            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];
                    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.TreeSet;
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;
            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);
                }
            }

            ob = new DSU(n);
            int mn = (int) 1e9;
            int mx = 0;
            ArrayList<Integer> ar1 = new ArrayList<>();
            for (i = 0; i < m; i++) {
                int u = store[hola[i].y][0];
                int v = store[hola[i].y][1];
                int w = hola[i].x;
                if (ob.find(u) != ob.find(v)) {
                    ob.unite(u, v);
                } else {
                    mn = Math.min(mn, w);
                }
                ar1.add(w);
                mx = Math.max(mx, w);
            }

            TreeSet<Integer> ar = new TreeSet<>();
            int cnt = 0;
            for (int xx : ar1) {
                if (xx > store[0][2]) {
                    ar.add(xx);
                    cnt++;
                }
                if (cnt == 5)
                    break;
            }
            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];
                    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.TreeSet;
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 i = 0;
            int[][] store = new int[m][3];
            int x = -1, y = -1;
            int haha = (int) 1e9;
            ArrayList<Integer> ar = new ArrayList<>();
            TreeSet<Integer> tset = new TreeSet<>();
            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();
                tset.add(store[i][2]);
                if (store[i][2] != haha)
                    tset.add(store[i][2] + 1);
            }
            tset.add(haha);
            for (int xx : tset)
                ar.add(xx);
            DSU ob = new DSU(n);

            int lo = 0, hi = ar.size() - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                PriorityQueue<Pair> pq = new PriorityQueue<>(com);
                pq.add(new Pair(ar.get(mid), 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 hola = pq.poll();
                    int u = store[hola.y][0];
                    int v = store[hola.y][1];
                    long w = hola.x;
                    if (ob.find(u) != ob.find(v)) {
                        ob.unite(u, v);
                        if (hola.y == 0) {
                            ok = true;
                            break;
                        }
                    }
                }
                if (ok)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            pn(ar.get(lo - 1));
        }

        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;
            }

        }

    }

    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.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);
                        Edge e = new Edge(u, v, w);
                        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(Math.min((int) mn + 1, (int) 1e9));
                ar.add(mx);
                ar.add(Math.min((int) mx + 1, (int) 1e9));
                ar.add((int) wt);
                ar.add(Math.min((int) wt + 1, (int) 1e9));
                ar.add(store[0][2]);
                ar.add(Math.min((int) store[0][2] + 1, (int) 1e9));
                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.PriorityQueue;
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 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();
            }
            DSU ob = new DSU(n);
            int haha = (int) 1e9;
            int lo = 0, hi = haha;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                PriorityQueue<Pair> pq = new PriorityQueue<>(com);
                pq.add(new Pair(mid, 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 hola = pq.poll();
                    int u = store[hola.y][0];
                    int v = store[hola.y][1];
                    long w = hola.x;
                    if (ob.find(u) != ob.find(v)) {
                        ob.unite(u, v);
                        if (hola.y == 0)
                            ok = true;
                    }
                }
                if (ok)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            pn(lo - 1);
        }

        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);
            }

            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;
            }

        }

    }

    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 i = 0;
            int x = -1, y = -1;
            Pair[] hola = new Pair[m];
            for (i = 0; i < m; i++) {
                int u = ni() - 1;
                int v = ni() - 1;
                hola[i] = new Pair(ni(), i, u, v);
            }
            DSU ob = new DSU(n);
            int haha = (int) 1e9;
            int lo = 0, hi = haha;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                for (i = 0; i < m; i++) {
                    if (hola[i].y == 0)
                        hola[i].x = mid;
                }
                ob.make_set(n);
                Arrays.sort(hola, com);
                boolean ok = false;
                for (i = 0; i < m; i++) {
                    int u = hola[i].a;
                    int v = hola[i].b;
                    if (ob.find(u) != ob.find(v)) {
                        ob.unite(u, v);
                        if (hola[i].y == 0)
                            ok = true;
                    }
                }
                if (ok)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            pn(lo - 1);
        }

        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;
                    rank[i] = 0;
                }
            }

            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;
            int a;
            int b;

            Pair(int p, int q, int s, int t) {
                x = p;
                y = q;
                a = s;
                b = t;
            }

        }

    }

    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.PriorityQueue;
import java.io.IOException;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.ArrayList;
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 i = 0;
            int[][] store = new int[m][3];
            int x = -1, y = -1;
            int haha = (int) 1e9;
            ArrayList<Integer> ar = new ArrayList<>();
            TreeSet<Integer> tset = new TreeSet<>();
            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();
                tset.add(store[i][2]);
                if (store[i][2] != haha)
                    tset.add(store[i][2] + 1);
            }
            tset.add(haha);
            for (int xx : tset)
                ar.add(xx);
            DSU ob = new DSU(n);

            int lo = 0, hi = ar.size() - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                PriorityQueue<Pair> pq = new PriorityQueue<>(com);
                pq.add(new Pair(ar.get(mid), 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 hola = pq.poll();
                    int u = store[hola.y][0];
                    int v = store[hola.y][1];
                    long w = hola.x;
                    if (ob.find(u) != ob.find(v)) {
                        ob.unite(u, v);
                        if (hola.y == 0)
                            ok = true;
                    }
                }
                if (ok)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            pn(ar.get(lo - 1));
        }

        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);
            }

            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;
            }

        }

    }

    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.PriorityQueue;
import java.io.IOException;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.ArrayList;
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 i = 0;
            int[][] store = new int[m][3];
            int x = -1, y = -1;
            int haha = (int) 1e9;
            ArrayList<Integer> ar = new ArrayList<>();
            TreeSet<Integer> tset = new TreeSet<>();
            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();
                tset.add(store[i][2]);
                if (store[i][2] != haha)
                    tset.add(store[i][2] + 1);
            }
            tset.add(haha);
            for (int xx : tset)
                ar.add(xx);
            DSU ob = new DSU(n);

            int lo = 0, hi = ar.size() - 1;
            while (lo <= hi) {
                int mid = (lo + hi) >> 1;
                PriorityQueue<Pair> pq = new PriorityQueue<>(com);
                pq.add(new Pair(ar.get(mid), 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 hola = pq.poll();
                    int u = store[hola.y][0];
                    int v = store[hola.y][1];
                    long w = hola.x;
                    if (ob.find(u) != ob.find(v)) {
                        ob.unite(u, v);
                        if (hola.y == 0) {
                            ok = true;
                            break;
                        }
                    }
                }
                if (ok)
                    lo = mid + 1;
                else
                    hi = mid - 1;
            }
            pn(ar.get(lo - 1));
        }

        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);
            }

            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;
            }

        }

    }

    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 {
        long INF = (long) 1e18 + 1;
        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 if (wt <= store[0][2])
                pn(wt);
            else {
                ob = new DSU(n);
                long mn = INF;
                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);
                        wt = Math.max(w, wt);
                        taken[hola[i].y] = true;
                    } else
                        mn = Math.min(mn, store[hola[i].y][2]);
                }
                pn(mn);
            }
        }

        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;
        }

    }
}