#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > c[220000];
struct node {
  int l, r, y, w, p;
  int operator<(const node &o) const {
    if (r != o.r) return r > o.r;
    return p < o.p;
  }
} s[220000];
int r[220000], ans[120000];
int n, m, top = 0;
int lowbit(int x) { return x & (-x); }
void ins(int x, pair<int, int> o) {
  while (x <= top) {
    c[x].insert(o);
    x += lowbit(x);
  }
}
pair<int, int> find(int x, int w) {
  pair<int, int> ans = make_pair(1999999999, -1);
  while (x > 0) {
    set<pair<int, int> >::iterator d = c[x].lower_bound(make_pair(w, 0));
    if (d != c[x].end()) {
      ans = min(ans, *d);
    }
    x -= lowbit(x);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n + m; i++) {
    scanf("%d%d%d", &s[i].l, &s[i].r, &s[i].w);
    s[i].p = i;
    r[++top] = s[i].l;
  }
  sort(r + 1, r + top + 1);
  top = unique(r + 1, r + top + 1) - r - 1;
  sort(s + 1, s + 1 + n + m);
  for (int i = 1; i <= n + m; i++) {
    s[i].l = lower_bound(r + 1, r + 1 + top, s[i].l) - r;
    if (s[i].p <= n) {
      ins(s[i].l, make_pair(s[i].w, s[i].p));
    } else {
      pair<int, int> g = find(s[i].l, s[i].w);
      ans[s[i].p - n] = g.second;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d ", ans[i]);
  return 0;
}
