#include <bits/stdc++.h>
using namespace std;
struct N {
  int l, r, t, id;
  N(int l = 0, int r = 0, int t = 0, int id = 0) : l(l), r(r), t(t), id(id) {}
  bool operator<(const N& rhp) const {
    if (l != rhp.l) return l < rhp.l;
    return id < rhp.id;
  }
};
int n, m, l, r, t, b[200005], sz = 0, res[200005];
int Mx[200005 << 2], V[200005 << 2];
vector<N> A;
int id(int x) { return lower_bound(b + 1, b + sz + 1, x) - b; }
void build(int o, int l, int r) {
  int mid = (l + r) / 2;
  if (l == r) {
    V[o] = Mx[o] = -1;
    return;
  }
  build(o << 1, l, mid);
  build(o << 1 | 1, mid + 1, r);
  Mx[o] = max(Mx[o << 1], Mx[o << 1 | 1]);
}
void ud(int o, int l, int r, int p, int v, int id) {
  int mid = (l + r) / 2;
  if (l == r) {
    Mx[o] = max(v, Mx[o]);
    V[o] = id;
    return;
  }
  if (p <= mid)
    ud(o << 1, l, mid, p, v, id);
  else
    ud(o << 1 | 1, mid + 1, r, p, v, id);
  Mx[o] = max(Mx[o << 1], Mx[o << 1 | 1]);
}
int qy(int o, int l, int r, int L, int R, int x) {
  int mid = (l + r) / 2;
  if (L <= l && r <= R) {
    if (l == r) {
      if (Mx[o] >= x)
        return V[o];
      else
        return -1;
    }
    if (Mx[o << 1] >= x)
      return qy(o << 1, l, mid, L, R, x);
    else if (Mx[o << 1 | 1] >= x)
      return qy(o << 1 | 1, mid + 1, r, L, R, x);
    else
      return -1;
  }
  int ans = -1;
  if (L <= mid) {
    ans = qy(o << 1, l, mid, L, R, x);
    if (ans != -1) return ans;
  }
  if (R > mid) ans = max(ans, qy(o << 1 | 1, mid + 1, r, L, R, x));
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n + m; i++) {
    scanf("%d%d%d", &l, &r, &t);
    A.push_back(N(l, r, t, i));
    b[++sz] = t;
  }
  sort(b + 1, b + sz + 1);
  sz = unique(b + 1, b + sz + 1) - (b + 1);
  build(1, 1, sz);
  sort(A.begin(), A.end());
  for (int i = 0; i < n + m; i++) {
    if (A[i].id <= n) {
      ud(1, 1, sz, id(A[i].t), A[i].r, A[i].id);
    } else {
      res[A[i].id] = qy(1, 1, sz, id(A[i].t), sz, A[i].r);
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d ", res[i + n]);
  }
}
