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.
#include <bits/stdc++.h>
using namespace std;
struct DisjointSet {
  int n, odd, fa[303030], sz[303030];
  vector<pair<int*, int> > h;
  vector<int> so;
  vector<int> sp;
  void init(int tn) {
    odd = n = tn;
    for (int i = 1; i <= n; i++) {
      fa[i] = i;
      sz[i] = 1;
    }
    so.clear();
    sp.clear();
    h.clear();
  }
  void assign(int* k, int v) {
    so.push_back(odd);
    h.push_back({k, *k});
    *k = v;
  }
  void save() { sp.push_back((int)((h).size())); }
  void undo() {
    assert(!sp.empty());
    int last = sp.back();
    sp.pop_back();
    while ((int)((h).size()) != last) {
      auto x = h.back();
      h.pop_back();
      odd = so.back();
      so.pop_back();
      *x.first = x.second;
    }
  }
  int f(int x) {
    while (fa[x] != x) x = fa[x];
    return x;
  }
  void uni(int x, int y) {
    x = f(x);
    y = f(y);
    if (x == y) return;
    if (sz[x] < sz[y]) swap(x, y);
    int nodd = odd - sz[x] % 2 - sz[y] % 2;
    assign(&sz[x], sz[x] + sz[y]);
    assign(&fa[y], x);
    odd = nodd + sz[x] % 2;
  }
} djs;
const int INF = 1023456789;
int n, m;
vector<pair<pair<int, int>, pair<int, int> > > v;
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int ai, bi, li;
    scanf("%d%d%d", &ai, &bi, &li);
    v.push_back({{li, i}, {ai, bi}});
  }
  sort(v.begin(), v.end());
}
int ans[303030];
void find_ans(int id,
              const vector<pair<pair<int, int>, pair<int, int> > >& tv) {
  for (auto e : tv)
    if (e.first.second <= id) {
      djs.uni(e.second.first, e.second.second);
      if (djs.odd == 0) {
        ans[id] = e.first.first;
        return;
      }
    }
}
void go(int l, int r, int cl, int cr,
        const vector<pair<pair<int, int>, pair<int, int> > >& tv) {
  if (l > r || cl > cr) return;
  if (cl == cr) {
    for (int i = l; i <= r; i++) ans[i] = cl;
    return;
  }
  djs.save();
  vector<pair<pair<int, int>, pair<int, int> > > wt;
  for (auto e : tv) {
    if (e.first.second < l && e.first.first < cl)
      djs.uni(e.second.first, e.second.second);
    else if (e.first.second <= r && e.first.first <= cr)
      wt.push_back(e);
  }
  int mid = (l + r) >> 1;
  ans[mid] = cr;
  djs.save();
  find_ans(mid, wt);
  djs.undo();
  go(l, mid - 1, ans[mid], cr, wt);
  go(mid + 1, r, cl, ans[mid], wt);
  djs.undo();
}
void solve() {
  djs.init(n);
  go(0, m - 1, 1, INF, v);
  for (int i = 0; i < m; i++) printf("%d\n", ans[i] == INF ? -1 : ans[i]);
}
int main() {
  init();
  solve();
}
