#include <bits/stdc++.h>
using namespace std;
struct foo {
  int l, r, t, i;
  foo() {}
  foo(int l, int r, int t, int i) : l(l), r(r), t(t), i(i) {}
  bool operator<(const foo& rhs) const { return l < rhs.l; }
};
const int INF = 0x7f7f7f7f;
const int MAXN = 200005;
struct SegTree {
  struct Node {
    int l, r;
    set<int> t;
    Node() { t.insert(INF); }
  } v[(((MAXN) << 1) | 1)];
  void build(int x, int l, int r) {
    v[x].l = l;
    v[x].r = r;
    if (l + 1 == r) return;
    int m = (l + r) / 2;
    build(((x) << 1), l, m);
    build((((x) << 1) | 1), m, r);
  }
  void update(int x, int r, int t) {
    if (v[x].l <= r && r < v[x].r) {
      v[x].t.insert(t);
      if (v[x].l + 1 == v[x].r) return;
      int m = ((v[x].l + v[x].r) >> 1);
      if (r < m)
        update(((x) << 1), r, t);
      else
        update((((x) << 1) | 1), r, t);
    }
  }
  int query(int x, int l, int r, int t) {
    if (l <= v[x].l && v[x].r <= r) {
      return *v[x].t.lower_bound(t);
    } else {
      int ret = INF, m = ((v[x].l + v[x].r) >> 1);
      if (l < m) ret = min(ret, query(((x) << 1), l, r, t));
      if (m < r) ret = min(ret, query((((x) << 1) | 1), l, r, t));
      return ret;
    }
  }
};
SegTree st;
int n, m;
vector<foo> b, c;
map<int, int> idx, bti;
int ans[MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int s, f, t;
    scanf("%d%d%d", &s, &f, &t);
    b.push_back(foo(s, f, t, i));
    idx[f];
    bti[t] = i + 1;
  }
  idx[INF];
  for (int i = 0; i < m; ++i) {
    int s, f, t;
    scanf("%d%d%d", &s, &f, &t);
    c.push_back(foo(s, f, t, i));
  }
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  map<int, int>::iterator it = idx.begin();
  for (int i = 0; it != idx.end(); ++i, ++it) {
    it->second = i;
  }
  for (int i = 0; i < n; ++i) {
    b[i].r = idx[b[i].r];
  }
  int sz = idx.size();
  st.build(1, 0, sz);
  for (int i = 0, j = 0; i < m; ++i) {
    for (; j < n && b[j].l <= c[i].l; ++j) {
      st.update(1, b[j].r, b[j].t);
    }
    int l = idx.lower_bound(c[i].r)->second;
    ans[c[i].i] = st.query(1, l, sz, c[i].t);
  }
  for (int i = 0; i < m; ++i) {
    printf("%d%c", (ans[i] == INF ? -1 : bti[ans[i]]),
           (i == m - 1 ? '\n' : ' '));
  }
}
