#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 100;
struct node {
  int l;
  int r;
  int sum;
  int id;
} p[maxx << 3];
struct Node {
  int l;
  int r;
  int t;
  int id;
  bool operator<(const Node &a) const {
    if (a.l != l)
      return a.l > l;
    else
      return a.id > id;
  }
} t[maxx << 1];
int a[maxx << 1], ans[maxx];
int n, m;
inline void pushup(int cur) {
  p[cur].sum = max(p[cur << 1].sum, p[cur << 1 | 1].sum);
}
inline void build(int l, int r, int cur) {
  p[cur].l = l;
  p[cur].r = r;
  p[cur].id = -1;
  p[cur].sum = -0x3f3f3f3f;
  if (l == r) return;
  int mid = l + r >> 1;
  build(l, mid, cur << 1);
  build(mid + 1, r, cur << 1 | 1);
}
inline void update(int pos, int r, int id, int cur) {
  int L = p[cur].l;
  int R = p[cur].r;
  if (L == R) {
    p[cur].sum = r;
    p[cur].id = id;
    return;
  }
  int mid = L + R >> 1;
  if (pos <= mid)
    update(pos, r, id, cur << 1);
  else
    update(pos, r, id, cur << 1 | 1);
  pushup(cur);
}
inline int query(int pos, int r, int cur) {
  int L = p[cur].l;
  int R = p[cur].r;
  if (p[cur].sum < r) return -1;
  if (L == R) {
    if (p[cur].sum >= r)
      return p[cur].id;
    else
      return -1;
  }
  int mid = L + R >> 1;
  if (pos <= mid) {
    int ans = -1;
    if (r <= p[cur << 1].sum) ans = query(pos, r, cur << 1);
    if (ans == -1) ans = query(pos, r, cur << 1 | 1);
    return ans;
  }
  return query(pos, r, cur << 1 | 1);
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n + m; i++) {
      scanf("%d%d%d", &t[i].l, &t[i].r, &t[i].t);
      t[i].id = i;
      a[i] = t[i].t;
    }
    sort(a + 1, a + 1 + n + m);
    int len = unique(a + 1, a + 1 + n + m) - a - 1;
    build(1, len, 1);
    sort(t + 1, t + 1 + n + m);
    for (int i = 1; i <= n + m; i++) {
      if (t[i].id <= n)
        update(lower_bound(a + 1, a + 1 + len, t[i].t) - a, t[i].r, t[i].id, 1);
      else
        ans[t[i].id - n] =
            query(lower_bound(a + 1, a + 1 + len, t[i].t) - a, t[i].r, 1);
    }
    for (int i = 1; i <= m; i++) printf("%d ", ans[i]);
    puts("");
  }
  return 0;
}
