#include <bits/stdc++.h>   using namespace std;   static const int len = 1000010;   struct event {     int t, x, y, tip, num;     event() {}     event(int _t, int _x, int _y, int _tip, int _num)         : t(_t), x(_x), y(_y), tip(_tip), num(_num) {}   };   bool compar(event one, event two) {     return ((one.x < two.x) || (one.x == two.x && one.tip > two.tip));   }   int n, m, globans;   int s[len], f[len], t[len];   int l[len], r[len], b[len], ans[len];   int tt[len * 4], xx[len * 4], tint[len * 4], xint[len * 4];   int tnum, xnum;   vector<event> a;   int tree[len * 4], number[len * 4];   int _count;   inline int findcord(int x) {     int left = 1, right = xnum;     while (left < right) {       int midle = (left + right + 1) / 2;       if (xx[midle] <= x)         left = midle;       else         right = midle - 1;     }     return xint[left];   }   inline int findtime(int x) {     int left = 1, right = tnum;     while (left < right) {       int midle = (left + right + 1) / 2;       if (tt[midle] <= x)         left = midle;       else         right = midle - 1;     }     return tint[left];   }   void update(int root, int l, int r, int x0, int len, int num) {     if (l == r) {       if (tree[root] < len) {         tree[root] = len;         number[root] = num;       }       return;     }     int m = (l + r) / 2;     if (x0 <= m)       update(root * 2, l, m, x0, len, num);     else       update(root * 2 + 1, m + 1, r, x0, len, num);     if (tree[root * 2] > tree[root]) {       tree[root] = tree[root * 2];       number[root] = number[root * 2];     }     if (tree[root * 2 + 1] > tree[root]) {       tree[root] = tree[root * 2 + 1];       number[root] = number[root * 2 + 1];     }   }   pair<int, int> _max(pair<int, int> a, pair<int, int> b) {     if (a.first >= b.first)       return a;     else       return b;   }   pair<int, int> getmax(int root, int l, int r, int L, int R) {     if (r < l || R < L) return make_pair(0, 0);     if (l == L && r == R) {       pair<int, int> t = make_pair(tree[root], number[root]);       return t;     }     int m = (l + r) / 2;     return _max(getmax(root * 2, l, m, L, min(m, R)),                 getmax(root * 2 + 1, m + 1, r, max(m + 1, L), R));   }   int findans(int root, int l, int r, int L, int R, int lim) {     if (r < l || R < L) return -1;     if (l == r) {       return number[root];     }     int m = (l + r) / 2;     pair<int, int> one = getmax(root * 2, l, m, L, min(m, R));     pair<int, int> two = getmax(root * 2 + 1, m + 1, r, max(m + 1, L), R);     if (one.first >= lim)       return findans(root * 2, l, m, L, min(m, R), lim);     else if (two.first >= lim)       return findans(root * 2 + 1, m + 1, r, max(m + 1, L), R, lim);     else       return -1;   }   int main() {     scanf( %d%d , &n, &m);     xnum = tnum = 0;     for (int i = (1); (i) <= (n); (i)++) {       scanf( %d%d%d , &s[i], &f[i], &t[i]);       tt[++tnum] = t[i];       xx[++xnum] = s[i];       xx[++xnum] = f[i];     }     for (int i = (1); (i) <= (m); (i)++) {       scanf( %d%d%d , &l[i], &r[i], &b[i]);       tt[++tnum] = b[i];       xx[++xnum] = l[i];       xx[++xnum] = r[i];       ans[i] = -1;     }     sort(xx + 1, xx + 1 + xnum);     sort(tt + 1, tt + 1 + tnum);     xint[1] = 1;     for (int i = (2); (i) <= (xnum); (i)++)       xint[i] = xint[i - 1] + int(xx[i] != xx[i - 1]);     tint[1] = 1;     for (int i = (2); (i) <= (tnum); (i)++)       tint[i] = tint[i - 1] + int(tt[i] != tt[i - 1]);     for (int i = (1); (i) <= (n); (i)++) {       s[i] = findcord(s[i]);       f[i] = findcord(f[i]);       t[i] = findtime(t[i]);       a.push_back(event(t[i], s[i], f[i], 1, i));     }     for (int i = (1); (i) <= (m); (i)++) {       l[i] = findcord(l[i]);       r[i] = findcord(r[i]);       b[i] = findtime(b[i]);       a.push_back(event(b[i], l[i], r[i], 0, i));     }     _count = tint[tnum];     sort(a.begin(), a.end(), compar);     for (int i = 0; i < a.size(); i++) {       if (a[i].tip == 0) {         int q = findans(1, 1, _count, a[i].t, _count, a[i].y);         ans[a[i].num] = q;       } else {         update(1, 1, _count, a[i].t, a[i].y, a[i].num);       }     }     for (int i = (1); (i) <= (m); (i)++) printf( %d n , ans[i]);     return 0;   }