#include <bits/stdc++.h>
const int N = 200010;
using namespace std;
int n, m, cnt = 0;
int ans[N];
struct nn {
  int l, r, t, id;
} a[N], hlp[N], tr[N << 2];
int hlpcmp(nn A, nn B) { return A.t < B.t; }
int cmp(nn A, nn B) {
  if (A.l == B.l) return A.id < B.id;
  return A.l < B.l;
}
void READ() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n + m; i++) {
    scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].t);
    a[i].id = i;
  }
  sort(a + 1, a + n + m + 1, cmp);
  for (int i = 1; i <= n + m; i++) hlp[i].id = i, hlp[i].t = a[i].t;
  sort(hlp + 1, hlp + n + m + 1, hlpcmp);
  hlp[0].t = hlp[1].t - 1;
  for (int i = 1; i <= n + m; i++) {
    if (hlp[i].t != hlp[i - 1].t) cnt++;
    a[hlp[i].id].t = cnt;
  }
}
void CHK(int x) {
  int l = x << 1, r = l | 1;
  tr[x].r = max(tr[l].r, tr[r].r);
}
void ADD(int x, int l, int r, int pos, int num) {
  if (l == r) {
    tr[x].r = a[num].r;
    tr[x].id = a[num].id;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos > mid)
    ADD((x << 1) | 1, mid + 1, r, pos, num);
  else
    ADD(x << 1, l, mid, pos, num);
  CHK(x);
}
int GET(int x, int l, int r, int la, int ra, int num) {
  if (tr[x].r < num) return -1;
  if (l == r) {
    if (tr[x].r >= num) return tr[x].id;
    return -1;
  }
  int mid = (l + r) >> 1;
  if (la > mid) return GET((x << 1) | 1, mid + 1, r, la, ra, num);
  if (ra <= mid) return GET(x << 1, l, mid, la, ra, num);
  int now = GET(x << 1, l, mid, la, mid, num);
  if (now != -1) return now;
  return GET((x << 1) | 1, mid + 1, r, mid + 1, ra, num);
}
void SOLVE() {
  for (int i = 1; i <= n + m; i++) {
    if (a[i].id <= n)
      ADD(1, 1, cnt, a[i].t, i);
    else
      ans[a[i].id - n] = GET(1, 1, cnt, a[i].t, cnt, a[i].r);
  }
  for (int i = 1; i <= m; i++) printf("%d ", ans[i]);
}
int main() {
  READ();
  SOLVE();
  return 0;
}
