In the land of Bovinia there are n pastures, but no paths connecting the pastures. Of course, this is a terrible situation, so Kevin Sun is planning to rectify it by constructing m undirected paths connecting pairs of distinct pastures. To make transportation more efficient, he also plans to pave some of these new paths.

Kevin is very particular about certain aspects of path-paving. Since he loves odd numbers, he wants each pasture to have an odd number of paved paths connected to it. Thus we call a paving sunny if each pasture is incident to an odd number of paved paths. He also enjoys short paths more than long paths, so he would like the longest paved path to be as short as possible. After adding each path, Kevin wants to know if a sunny paving exists for the paths of Bovinia, and if at least one does, the minimum possible length of the longest path in such a paving. Note that "longest path" here means maximum-weight edge.

Input

The first line contains two integers n (2 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 300 000), denoting the number of pastures and paths, respectively. The next m lines each contain three integers ai, bi and li, describing the i-th path. The i-th path connects pastures ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) and has length li (1 ≤ li ≤ 109). Paths are given in the order in which they are constructed. 

Output

Output m lines. The i-th line should contain a single integer denoting the minimum possible length of the longest path (maximum-weight edge) in a sunny paving using only the first i paths. If Kevin cannot pave a set of paths so that each pasture is incident to an odd number of paved paths, output  - 1.

Note that the paving is only hypothetical—your answer after adding the i-th path should not be affected by any of your previous answers.

Examples

Input

4 4
1 3 4
2 4 8
1 2 2
3 4 3


Output

-1
8
8
3


Input

3 2
1 2 3
2 3 4


Output

-1
-1


Input

4 10
2 1 987
3 2 829
4 1 768
4 2 608
3 4 593
3 2 488
4 2 334
2 1 204
1 3 114
1 4 39


Output

-1
-1
829
829
768
768
768
488
334
204

Note

For the first sample, these are the paths that Kevin should pave after building the i-th path: 

  1. No set of paths works. 
  2. Paths 1 (length 4) and 2 (length 8). 
  3. Paths 1 (length 4) and 2 (length 8). 
  4. Paths 3 (length 2) and 4 (length 3). 



In the second sample, there never exists a paving that makes Kevin happy.
import java.io.*;
import java.util.*;

public class E {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	static boolean odd(int x) {
		return (x & 1) == 1;
	}

	static class DSU {

		private int[] histU;
		private int[] histPu;

		int time;

		int[] p;
		int cntOdd;

		boolean check() {
			return cntOdd == 0;
		}

		boolean union(int v, int u) {
			while (p[v] >= 0) {
				v = p[v];
			}
			while (p[u] >= 0) {
				u = p[u];
			}
			if (v == u) {
				return false;
			}
			if (p[v] > p[u]) {
				int tmp = v;
				v = u;
				u = tmp;
			}
			histU[time] = u;
			histPu[time] = p[u];
			time++;
			if (odd(p[v] & p[u])) {
				cntOdd -= 2;
			}
			p[v] += p[u];
			p[u] = v;
			return check();
		}

		void rollback(int to) {
			while (time > to) {
				--time;
				int u = histU[time];
				int pu = histPu[time];
				int v = p[u];
				p[v] -= pu;
				if (odd(p[v] & pu)) {
					cntOdd += 2;
				}
				p[u] = pu;
			}
		}

		public DSU(int n) {
			p = new int[n];
			Arrays.fill(p, -1);
			histU = new int[n - 1];
			histPu = new int[n - 1];
			cntOdd = n;
		}
	}

	static class Edge implements Comparable<Edge> {
		int v1, v2, len, order, lenRank;

		public Edge(int v1, int v2, int len) {
			this.v1 = v1;
			this.v2 = v2;
			this.len = len;
		}

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

	Edge[] es, esLen;
	int[] ans;
	
	int n, m;
	
	void go(int l1, int r1, int l2, int r2, DSU dsu) {

		if (r1 - l1 < 1) {
			return;
		}


		int mid = (l1 + r1) >> 1;
		int midAns = r2;

		int state = dsu.time;
		
		for (int i = l1; i <= mid; i++) {
			if (es[i].lenRank < l2) {
				dsu.union(es[i].v1, es[i].v2);
			}
		}

		for (int i = l2; i < r2; i++) {
			if (esLen[i].order <= mid) {
				if (dsu.union(esLen[i].v1, esLen[i].v2)) {
					midAns = i;
					break;
				}
			}
		}

		ans[mid] = midAns;

		dsu.rollback(state);

		if (midAns == r2) {
			for (int i = l1; i < mid; i++) {
				ans[i] = midAns;
			}
		} else {
			for (int i = l2; i < midAns; i++) {
				if (esLen[i].order < l1) {
					dsu.union(esLen[i].v1, esLen[i].v2);
				}
			}
			go(l1, mid, midAns, r2, dsu);
		}

		dsu.rollback(state);

		for (int i = l1; i <= mid; i++) {
			if (es[i].lenRank < l2) {
				dsu.union(es[i].v1, es[i].v2);
			}
		}
		go(mid + 1, r1, l2, Math.min(midAns + 1, m), dsu);

		dsu.rollback(state);
	}

	void solve() throws IOException {
		n = nextInt();
		m = nextInt();

		es = new Edge[m];
		for (int i = 0; i < m; i++) {
			int v1 = nextInt() - 1;
			int v2 = nextInt() - 1;
			int len = nextInt();
			es[i] = new Edge(v1, v2, len);
			es[i].order = i;
		}

		esLen = es.clone();
		Arrays.sort(esLen);

		for (int i = 0; i < m; i++) {
			esLen[i].lenRank = i;
		}

		DSU dsu = new DSU(n);

		ans = new int[m];
		go(0, m, 0, m, dsu);

		for (int i = 0; i < m; i++) {
			out.println(ans[i] == m ? -1 : esLen[ans[i]].len);
		}
	}

	E() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

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

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

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

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

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