#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
const int INF = 1000000005;
struct P {
  int l, r, mid;
  map<int, int> lzs;
} arr[4 * N];
struct PP {
  int l, r, t, id;
} bus[N], per[N];
bool cmp(PP x, PP y) { return x.r < y.r; }
void build(int L, int R, int c) {
  arr[c].l = L;
  arr[c].r = R;
  arr[c].mid = (L + R) / 2;
  arr[c].lzs[INF] = -1;
  if (L == R) return;
  build(L, arr[c].mid, c + c);
  build(arr[c].mid + 1, R, c + c + 1);
}
void insert(int x, int v, int id, int c) {
  arr[c].lzs[v] = id;
  if (x >= arr[c].r) {
    return;
  }
  if (x <= arr[c].mid)
    insert(x, v, id, c + c);
  else
    insert(x, v, id, c + c + 1);
}
int res, rid;
map<int, int>::iterator it;
void find(int R, int v, int c) {
  if (R >= arr[c].r) {
    it = arr[c].lzs.lower_bound(v);
    if (res >= (it->first)) {
      res = (it->first);
      rid = (it->second);
    }
    return;
  }
  find(R, v, c + c);
  if (R > arr[c].mid) find(R, v, c + c + 1);
}
int a[N], b[N], pp, n, m;
bool cmpp(int x, int y) { return a[x] < a[y]; }
void get(int id) {
  if (id >= n + n) {
    id -= n + n;
    if (id % 2 == 0)
      per[id / 2].l = pp;
    else
      per[id / 2].r = pp;
  } else {
    if (id % 2 == 0)
      bus[id / 2].l = pp;
    else
      bus[id / 2].r = pp;
  }
}
int re[N];
int main() {
  int i, j, l;
  scanf("%d%d", &n, &m);
  int k = 0;
  for (i = 0; i < n; i++) {
    scanf("%d%d%d", &a[k], &a[k + 1], &bus[i].t);
    bus[i].id = i + 1;
    k += 2;
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &a[k], &a[k + 1], &per[i].t);
    per[i].id = i;
    k += 2;
  }
  for (i = 0; i < k; i++) b[i] = i;
  sort(b, b + k, cmpp);
  pp = 1;
  get(b[0]);
  for (i = 1; i < k; i++) {
    if (a[b[i]] != a[b[i - 1]]) ++pp;
    get(b[i]);
  }
  sort(bus, bus + n, cmp);
  sort(per, per + m, cmp);
  k = pp;
  build(1, k, 1);
  for (j = n - 1, i = m - 1; i >= 0; i--) {
    while (j >= 0 && bus[j].r >= per[i].r) {
      insert(bus[j].l, bus[j].t, bus[j].id, 1);
      j--;
    }
    res = INF;
    find(per[i].l, per[i].t, 1);
    re[per[i].id] = rid;
  }
  for (i = 0; i < m - 1; i++) printf("%d ", re[i]);
  printf("%d\n", re[i]);
  return 0;
}
