#include <bits/stdc++.h>
using namespace std;
int n, m, ans[1 << 18], timp[1 << 18], tr[1 << 21], td[1 << 21];
struct pt {
  int l, r, t, id;
} q[1 << 18];
bool cmp(pt a, pt b) {
  if (a.l == b.l) return a.id > b.id;
  return a.l < b.l;
}
void Update(int t, int l, int r, int x, int vr, int vi) {
  if (l == r) {
    tr[t] = vr;
    td[t] = vi;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) Update(t << 1, l, mid, x, vr, vi);
  if (x > mid) Update(t << 1 | 1, mid + 1, r, x, vr, vi);
  tr[t] = max(tr[t << 1], tr[t << 1 | 1]);
}
int Query(int t, int l, int r, int vr, int x) {
  if (vr > tr[t]) return -1;
  if (l == r) return td[t];
  int rez = -1;
  int mid = (l + r) >> 1;
  if (x <= mid) {
    rez = Query(t << 1, l, mid, vr, x);
    if (rez > 0) return rez;
  }
  return Query(t << 1 | 1, mid + 1, r, vr, x);
}
int main() {
  scanf("%d%d", &n, &m);
  int k = m;
  for (int i = 1; i <= n; ++i) {
    ++k;
    scanf("%d%d%d", &q[k].l, &q[k].r, &q[k].t);
    q[k].id = k;
    timp[k] = q[k].t;
  }
  k = 0;
  for (int i = 1; i <= m; ++i) {
    ++k;
    scanf("%d%d%d", &q[k].l, &q[k].r, &q[k].t);
    q[k].id = k;
    timp[k] = q[k].t;
  }
  k = n + m;
  sort(q + 1, q + k + 1, cmp);
  sort(timp + 1, timp + k + 1);
  for (int i = 1; i <= n + m; ++i) {
    int xx = lower_bound(timp + 1, timp + 1 + k, q[i].t) - timp;
    if (q[i].id <= m)
      ans[q[i].id] = Query(1, 1, k, q[i].r, xx);
    else
      Update(1, 1, k, xx, q[i].r, q[i].id - m);
  }
  for (int i = 1; i <= m; ++i) printf("%d ", ans[i]);
  return 0;
}
