#include <bits/stdc++.h>
using namespace std;
const int Mx = 1e5 + 5;
struct Buses {
  long long l, r, t, id;
} buses[Mx];
struct Person {
  long long l, r, t, id;
} person[Mx];
long long ans[Mx], t[Mx << 1];
int n, m;
class SegTree {
 public:
  inline void buildSegTree(int k, int l, int r) {
    segnode[k].l = l;
    segnode[k].r = r;
    if (l == r) return;
    int mid = (l + r) >> 1;
    buildSegTree(k << 1, l, mid);
    buildSegTree(k << 1 | 1, mid + 1, r);
  }
  inline void opi(int i) {
    int id = lower_bound(t + 1, t + n + m + 1, buses[i].t) - t;
    insert(1, id, buses[i].id, buses[i].r);
  }
  inline void ops(int i) {
    int id = lower_bound(t + 1, t + n + m + 1, person[i].t) - t;
    ans[person[i].id] = search(1, id, person[i].r);
  }

 private:
  struct SegNode {
    int l, r, id;
    long long v;
  } segnode[Mx << 3];
  void pushUp(int k) {
    segnode[k].v = max(segnode[k << 1].v, segnode[k << 1 | 1].v);
  }
  inline void insert(int k, int pos, int id, long long v) {
    int sl = segnode[k].l, sr = segnode[k].r;
    if (sl == sr) {
      segnode[k].v = v;
      segnode[k].id = id;
      return;
    }
    int mid = (sl + sr) >> 1;
    if (pos <= mid) insert(k << 1, pos, id, v);
    if (pos > mid) insert(k << 1 | 1, pos, id, v);
    pushUp(k);
  }
  inline int search(int k, int pos, long long v) {
    int sl = segnode[k].l, sr = segnode[k].r;
    if (segnode[k].v < v) return -1;
    if (segnode[k].r < pos) return -1;
    if (sl == sr) return segnode[k].id;
    int mid = (sl + sr) >> 1;
    int res = search(k << 1, pos, v);
    return res == -1 ? search(k << 1 | 1, pos, v) : res;
  }
};
SegTree T;
template <class T>
bool cmp(T a, T b) {
  return a.l < b.l;
};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%lld%lld%lld", &buses[i].l, &buses[i].r, &buses[i].t),
        buses[i].id = i;
  for (int i = 1; i <= m; i++)
    scanf("%lld%lld%lld", &person[i].l, &person[i].r, &person[i].t),
        person[i].id = i;
  T.buildSegTree(1, 1, n + m);
  for (int i = 1; i <= n; i++) t[i] = buses[i].t;
  for (int i = n + 1; i <= n + m; i++) t[i] = person[i - n].t;
  sort(t + 1, t + 1 + n + m);
  sort(buses + 1, buses + 1 + n, cmp<Buses>);
  sort(person + 1, person + 1 + m, cmp<Person>);
  int bi = 1, pi = 1;
  while (bi <= n || pi <= m) {
    if (pi > m) break;
    if (bi > n || buses[bi].l > person[pi].l)
      T.ops(pi), pi++;
    else
      T.opi(bi), bi++;
  }
  for (int i = 1; i <= m; i++) printf("%lld ", ans[i]);
}
