#include <bits/stdc++.h>
const int N = 200010;
const int inf = 0x3f3f3f3f;
using namespace std;
struct seg_tree {
  struct node {
    int l, r;
    pair<int, int> k;
  } tree[N * 4];
  void b_tree(int l, int r, int idx) {
    tree[idx].l = l;
    tree[idx].r = r;
    tree[idx].k = make_pair(inf, l);
    if (l == r) return;
    int mid = (l + r) >> 1;
    b_tree(l, mid, idx << 1);
    b_tree(mid + 1, r, idx << 1 | 1);
  }
  void insert(int x, int y, int idx) {
    if (tree[idx].l == tree[idx].r) {
      tree[idx].k = make_pair(y, x);
      return;
    }
    int mid = (tree[idx].l + tree[idx].r) >> 1;
    if (x <= mid)
      insert(x, y, idx << 1);
    else
      insert(x, y, idx << 1 | 1);
    tree[idx].k = min(tree[idx << 1].k, tree[idx << 1 | 1].k);
    return;
  }
  pair<int, int> query(int l, int r, int idx) {
    if (tree[idx].l == l && tree[idx].r == r) return tree[idx].k;
    int mid = (tree[idx].l + tree[idx].r) >> 1;
    if (r <= mid)
      return query(l, r, idx << 1);
    else if (l > mid)
      return query(l, r, idx << 1 | 1);
    return min(query(l, mid, idx << 1), query(mid + 1, r, idx << 1 | 1));
  }
} seg;
pair<int, int> l[N];
int res[N];
struct data {
  int l, r, t, id;
  bool operator<(const data &r) const { return t < r.t; }
  void out() { cout << l << " " << r << " " << t << " " << id << endl; }
} man[N], bus[N];
int main() {
  memset(res, -1, sizeof(res));
  map<pair<int, int>, int> hh;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    scanf("%d%d%d", &bus[i].l, &bus[i].r, &bus[i].t),
        l[i] = make_pair(bus[i].l, i), bus[i].id = i;
  for (int i = 0; i < m; i++)
    scanf("%d%d%d", &man[i].l, &man[i].r, &man[i].t),
        l[i + n] = make_pair(man[i].l, i + n), man[i].id = i + n;
  sort(bus, bus + n);
  sort(man, man + m);
  sort(l, l + n + m);
  for (int i = 0; i < n + m; i++) hh[l[i]] = i + 1;
  seg.b_tree(1, m + n, 1);
  for (int i = 0, j = 0; i < n; i++) {
    while (j < m && man[j].t <= bus[i].t) {
      seg.insert(hh[make_pair(man[j].l, man[j].id)], man[j].r, 1), j++;
    }
    pair<int, int> tt;
    while (tt = seg.query(hh[make_pair(bus[i].l, bus[i].id)], m + n, 1),
           tt.first <= bus[i].r)
      res[l[tt.second - 1].second] = bus[i].id + 1,
                        seg.insert(tt.second, inf, 1);
  }
  for (int i = n; i < m + n; i++) printf("%d ", res[i]);
  puts("");
  return 0;
}
