#include <bits/stdc++.h>
using namespace std;
int sol[100100];
pair<pair<int, int>, pair<int, int> > bus[100100], cit[100100];
int n, m, po;
struct Tr {
  Tr *l, *r;
  int mi, val, key, pr, ind;
  Tr(int _key, int _val, int _ind) {
    val = _val;
    key = _key;
    pr = rand();
    mi = val;
    l = r = NULL;
    ind = _ind;
  };
};
Tr *R;
int mi(Tr *&t) {
  if (!t) return 1 << 30;
  return t->mi;
}
void upd(Tr *&t) {
  if (!t) return;
  t->mi = min(t->val, min(mi(t->l), mi(t->r)));
}
void merge(Tr *&t, Tr *l, Tr *r) {
  if (!l || !r)
    t = l ? l : r;
  else {
    if (l->pr > r->pr)
      merge(l->r, l->r, r), t = l;
    else
      merge(r->l, l, r->l), t = r;
  }
  upd(t);
}
void split(Tr *t, Tr *&l, Tr *&r, int key) {
  if (!t)
    l = r = NULL;
  else if (key <= t->key)
    split(t->l, l, t->l, key), r = t;
  else
    split(t->r, t->r, r, key), l = t;
  upd(t);
}
void insert(Tr *&t, Tr *it) {
  if (!t)
    t = it;
  else if (it->pr > t->pr)
    split(t, it->l, it->r, it->key), t = it;
  else if (it->key == t->key) {
    if (rand() % 2)
      insert(t->l, it);
    else
      insert(t->r, it);
  } else if (it->key > t->key)
    insert(t->r, it);
  else
    insert(t->l, it);
  upd(t);
}
void dfs(Tr *&t, int va, int bus) {
  if (!t) return;
  if (mi(t->l) <= va) dfs(t->l, va, bus);
  if (mi(t->r) <= va) dfs(t->r, va, bus);
  if (t->val <= va) {
    sol[t->ind] = bus;
    merge(t, t->l, t->r);
  }
  upd(t);
}
void query(int st, int dr, int bus) {
  Tr *t1, *t2, *t3;
  split(R, t1, t2, st);
  split(t2, t2, t3, dr + 1);
  dfs(t2, dr, bus);
  merge(R, t1, t2);
  merge(R, R, t3);
}
int main() {
  cin >> n >> m;
  for (register int i = 1; i <= n; ++i) {
    cin >> bus[i].second.first >> bus[i].second.second >> bus[i].first.first;
    bus[i].first.second = i;
  }
  sort(bus + 1, bus + n + 1);
  for (register int i = 1; i <= m; ++i) {
    cin >> cit[i].second.first >> cit[i].second.second >> cit[i].first.first;
    cit[i].first.second = i;
  }
  sort(cit + 1, cit + m + 1);
  po = 1;
  for (register int i = 1; i <= m; ++i) sol[i] = -1;
  for (register int i = 1; i <= n; ++i) {
    while (po <= m && cit[po].first.first <= bus[i].first.first) {
      Tr *it = new Tr(cit[po].second.first, cit[po].second.second,
                      cit[po].first.second);
      insert(R, it);
      ++po;
    }
    query(bus[i].second.first, bus[i].second.second, bus[i].first.second);
  }
  for (register int i = 1; i <= m; ++i) cout << sol[i] << " ";
  return 0;
}
