#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
struct node {
  int l, r, t, i;
} a[maxn * 3];
int tree[maxn * 8];
int ti[maxn];
int id[maxn];
int ans[maxn];
bool cmp(node a, node b) {
  if (a.l != b.l)
    return a.l < b.l;
  else
    return a.i < b.i;
}
int find(int x, int y, int z) {
  if (x > y) return -1;
  int mid = (x + y) / 2;
  if (ti[mid] >= z) {
    int t = find(x, mid - 1, z);
    if (t == -1)
      return mid;
    else
      return t;
  } else
    return find(mid + 1, y, z);
}
void insert(int v, int pos, int idd, int l, int r, int z) {
  int mid = (l + r) / 2;
  if (l == r) {
    tree[z] = v;
    id[z] = idd;
    return;
  }
  if (pos <= mid)
    insert(v, pos, idd, l, mid, z * 2);
  else {
    insert(v, pos, idd, mid + 1, r, z * 2 + 1);
  }
  tree[z] = tree[z * 2] > tree[z * 2 + 1] ? tree[z * 2] : tree[z * 2 + 1];
}
int search(int v, int pos, int l, int r, int z) {
  if (tree[z] < v) return -1;
  if (l == r) {
    return id[z];
  }
  int mid = (l + r) / 2;
  if (pos <= mid) {
    int t = search(v, pos, l, mid, z * 2);
    if (t != -1) return t;
  }
  return search(v, pos, mid + 1, r, z * 2 + 1);
}
int main() {
  memset(id, -1, sizeof(id));
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n + m; i++) {
    scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].t);
    a[i].i = i;
    ti[i] = a[i].t;
  }
  sort(a + 1, a + 1 + m + n, cmp);
  sort(ti + 1, ti + 1 + m + n);
  for (int i = 1; i <= n + m; i++) {
    int pos = find(1, n + m, a[i].t);
    if (a[i].i <= n)
      insert(a[i].r, pos, a[i].i, 1, n + m, 1);
    else
      ans[a[i].i - n] = search(a[i].r, pos, 1, n + m, 1);
  }
  for (int i = 1; i < m; i++) {
    printf("%d ", ans[i]);
  }
  printf("%d\n", ans[m]);
  return 0;
}
