#include <bits/stdc++.h>
using std::lower_bound;
using std::max;
using std::sort;
const int N = 222000;
int n, m;
int rmax[N << 2], id[N << 2], tt[N << 1], answer[N];
struct node {
  int l, r, t, id;
  bool operator<(const node tmp) const {
    return (l < tmp.l) || (l == tmp.l && id < tmp.id);
  }
} L[N << 1];
void PushUp(int t) { rmax[t] = max(rmax[t << 1], rmax[t << 1 | 1]); }
void update(int L, int Raim, int idx, int l, int r, int t) {
  if (l == r) {
    rmax[t] = Raim;
    id[t] = idx;
    return;
  }
  int m = (l + r) >> 1;
  if (L <= m)
    update(L, Raim, idx, l, m, t << 1);
  else
    update(L, Raim, idx, m + 1, r, t << 1 | 1);
  rmax[t] = max(rmax[t << 1], rmax[t << 1 | 1]);
}
int query(int pos, int Raim, int l, int r, int t) {
  if (Raim > rmax[t]) return -1;
  if (l == r) return id[t];
  int ans = -1;
  int m = (l + r) >> 1;
  if (pos <= m) {
    ans = query(pos, Raim, l, m, t << 1);
    if (ans > 0) return ans;
  }
  return query(pos, Raim, m + 1, r, t << 1 | 1);
}
int main() {
  while (~scanf("%d %d", &n, &m)) {
    for (int i = 1; i <= n + m; i++) {
      scanf("%d %d %d", &L[i].l, &L[i].r, &L[i].t);
      L[i].id = i;
      tt[i] = L[i].t;
    }
    sort(tt + 1, tt + n + m + 1);
    sort(L + 1, L + n + m + 1);
    for (int i = 1; i <= n + m + 1; i++) {
      int p = lower_bound(tt + 1, tt + n + m + 1, L[i].t) - tt;
      if (L[i].id <= n)
        update(p, L[i].r, L[i].id, 1, n + m, 1);
      else
        answer[L[i].id - n] = query(p, L[i].r, 1, n + m, 1);
    }
    for (int i = 1; i < m; i++) printf("%d ", answer[i]);
    printf("%d\n", answer[m]);
  }
  return 0;
}
