#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100005;   const int MaxM = MaxN * 2;   const int oo = 0x3F3F3F3F;   int ax[MaxM], K;   int ret[MaxN];   set<pair<int, int> > tr[MaxM];   struct event {     int l, r, v, tp;     event() {}     event(int l, int r, int v, int tp) : l(l), r(r), v(v), tp(tp) {}     bool operator<(const event& e) const {       if (r != e.r)         return r > e.r;       else         return tp < e.tp;     }   } e[MaxM];   int getId(int v) { return lower_bound(ax, ax + K, v) - ax + 1; }   void add(int k, pair<int, int> v) {     while (k <= K) {       tr[k].insert(v);       k += k & -k;     }   }   int read(int k, int v) {     pair<int, int> ret = make_pair(oo, -1);     while (k) {       set<pair<int, int> >::iterator it = tr[k].lower_bound(make_pair(v, 0));       if (it != tr[k].end()) ret = min(ret, *it);       k -= k & -k;     }     return ret.second;   }   int main() {     int N, M, en;     int l, r, t;     scanf( %d%d , &N, &M);     K = en = 0;     for (int i = 0; i < N; i++) {       scanf( %d%d%d , &l, &r, &t);       e[en++] = event(l, r, t, -i - 1);       ax[K++] = l;     }     for (int i = 0; i < M; i++) {       scanf( %d%d%d , &l, &r, &t);       e[en++] = event(l, r, t, i);       ax[K++] = l;     }     sort(ax, ax + K);     K = unique(ax, ax + K) - ax;     sort(e, e + en);     for (int i = 0; i < en; i++) {       if (e[i].tp < 0) {         add(getId(e[i].l), make_pair(e[i].v, -e[i].tp));       } else {         ret[e[i].tp] = read(getId(e[i].l), e[i].v);       }     }     for (int i = 0; i < M; i++) {       printf( %d  , ret[i]);     }     puts(  );     return 0;   }   