#include <bits/stdc++.h>
using namespace std;
int n, m, sz[600001], tot, L[600001], R[600001], root, id[600001], val[600001];
map<int, int> M;
struct dance {
  int id, l, r, t;
} xx[600001];
bool cmp(dance x, dance y) {
  return (x.l < y.l || (x.l == y.l && x.id < y.id));
}
void build(int no, int l, int r) {
  L[no] = l;
  R[no] = r;
  if (l == r) return;
  int mid = (L[no] + R[no]) >> 1;
  build(no << 1, l, mid);
  build(no << 1 | 1, mid + 1, r);
}
void add(int no, int num, int c, int pos) {
  if (L[no] == R[no]) {
    val[no] = c;
    id[no] = num;
    return;
  }
  int mid = (L[no] + R[no]) >> 1;
  if (pos > mid)
    add(no << 1 | 1, num, c, pos);
  else
    add(no << 1, num, c, pos);
  val[no] = max(val[no << 1], val[no << 1 | 1]);
}
int query(int no, int num, int l, int r) {
  if (val[no] < num) return -1;
  if (L[no] == R[no]) return id[no];
  int mid = (L[no] + R[no]) >> 1;
  if (l > mid) return query(no << 1 | 1, num, l, r);
  if (r <= mid) return query(no << 1, num, l, r);
  int lq = query(no << 1, num, l, mid);
  if (lq != -1) return lq;
  return query(no << 1 | 1, num, mid + 1, r);
}
int ans[600001];
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &xx[i].l);
    scanf("%d", &xx[i].r);
    scanf("%d", &xx[i].t);
    xx[i].id = i;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &xx[i + n].l);
    scanf("%d", &xx[i + n].r);
    scanf("%d", &xx[i + n].t);
    xx[i + n].id = i + n;
  }
  sort(xx + 1, xx + n + m + 1, cmp);
  for (int i = 1; i <= n + m; i++) {
    if (!M.count(xx[i].t)) {
      sz[++tot] = xx[i].t, M[xx[i].t] = tot;
    }
  }
  sort(sz + 1, sz + tot + 1);
  for (int i = 1; i <= tot; i++) {
    M[sz[i]] = i;
  }
  build(1, 1, tot);
  for (int i = 1; i <= n + m; i++) {
    int pos = M[xx[i].t];
    if (xx[i].id <= n) {
      add(1, xx[i].id, xx[i].r, pos);
    } else {
      ans[xx[i].id - n] = query(1, xx[i].r, pos, tot);
    }
  }
  for (int i = 1; i <= m; i++) printf("%d ", ans[i]);
}
