#include <bits/stdc++.h>
using namespace std;
const int maxn = 222222;
int rmax[maxn << 2];
int id[maxn << 2];
int n, m;
struct seg {
  int l, r, t, id;
  seg(){};
  bool operator<(const seg cmp) const {
    return (l < cmp.l || l == cmp.l && id < cmp.id);
  }
} a[maxn * 2];
int max(int a, int b) { return a > b ? a : b; }
void update(int pos, int rval, int idx, int l, int r, int rt) {
  if (l == r) {
    rmax[rt] = rval;
    id[rt] = idx;
    return;
  }
  int m = (l + r) >> 1;
  if (m >= pos)
    update(pos, rval, idx, l, m, rt << 1);
  else
    update(pos, rval, idx, m + 1, r, rt << 1 | 1);
  rmax[rt] = max(rmax[rt << 1], rmax[rt << 1 | 1]);
}
int query(int pos, int rval, int l, int r, int rt) {
  if (rmax[rt] < rval) return -1;
  if (l == r) return id[rt];
  int ret = -1;
  int m = (l + r) >> 1;
  if (m >= pos) {
    ret = query(pos, rval, l, m, rt << 1);
    if (ret > 0) return ret;
  }
  return query(pos, rval, m + 1, r, rt << 1 | 1);
}
int tt[maxn * 2];
int ans[maxn * 2];
int main() {
  int i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n + m; i++) {
    scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].t);
    a[i].id = i;
    tt[i] = a[i].t;
  }
  sort(a + 1, a + n + m + 1);
  sort(tt + 1, tt + n + m + 1);
  for (i = 1; i <= n + m; i++) {
    int pos = lower_bound(tt + 1, tt + n + m + 1, a[i].t) - tt;
    if (a[i].id <= n)
      update(pos, a[i].r, a[i].id, 1, n + m, 1);
    else
      ans[a[i].id - n] = query(pos, a[i].r, 1, n + m, 1);
  }
  for (i = 1; i <= m; i++) printf("%d ", ans[i]);
  return 0;
}
