#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 * 6 + 10;
const int INF = 1e9 + 10;
int a[maxn];
int Max[maxn << 2];
int T[maxn];
struct Bus {
  int s, f, t, id;
  void read(int i) {
    scanf("%d%d%d", &s, &f, &t);
    id = i;
  }
  bool operator<(const Bus& rhs) const { return s < rhs.s; }
} bus[maxn + 10];
struct Peo {
  int l, r, b, id, ans;
  void read(int i) {
    scanf("%d%d%d", &l, &r, &b);
    id = i;
    ans = 0;
  }
  bool operator<(const Peo& rhs) const { return l < rhs.l; }
} peo[maxn + 10];
bool cmp(const Peo& A, const Peo& B) { return A.id < B.id; }
void build(int l, int r, int rt) {
  if (l == r) {
    Max[rt] = -1;
  } else {
    int m = (l + r) >> 1;
    build(l, m, rt << 1);
    build(m + 1, r, rt << 1 | 1);
    Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]);
  }
}
void update(int p, int x, int l, int r, int rt) {
  if (l == r) {
    Max[rt] = x;
  } else {
    int m = (l + r) >> 1;
    if (p <= m)
      update(p, x, l, m, rt << 1);
    else
      update(p, x, m + 1, r, rt << 1 | 1);
    Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]);
  }
}
int query(int ql, int qr, int cnt, int l, int r, int rt) {
  if (Max[rt] < cnt) return -1;
  if (l == r) {
    return Max[rt] >= cnt ? l : -1;
  }
  int m = (l + r) >> 1;
  int ans = INF;
  if (ql <= m) {
    int ans1 = query(ql, qr, cnt, l, m, rt << 1);
    if (ans1 != -1) ans = ans1;
  }
  if (m < qr && ans == INF) {
    int ans1 = query(ql, qr, cnt, m + 1, r, rt << 1 | 1);
    if (ans1 != -1) ans = min(ans, ans1);
  }
  return ans == INF ? -1 : ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    bus[i].read(i + 1);
    a[cnt++] = bus[i].s;
    a[cnt++] = bus[i].f;
    a[cnt++] = bus[i].t;
  }
  for (int i = 0; i < m; i++) {
    peo[i].read(i + 1);
    a[cnt++] = peo[i].l;
    a[cnt++] = peo[i].r;
    a[cnt++] = peo[i].b;
  }
  sort(a, a + cnt);
  int len = unique(a, a + cnt) - a;
  for (int i = 0; i < n; i++) {
    bus[i].s = upper_bound(a, a + len, bus[i].s) - a;
    bus[i].f = upper_bound(a, a + len, bus[i].f) - a;
    bus[i].t = upper_bound(a, a + len, bus[i].t) - a;
    T[bus[i].t] = bus[i].id;
  }
  for (int i = 0; i < m; i++) {
    peo[i].l = upper_bound(a, a + len, peo[i].l) - a;
    peo[i].r = upper_bound(a, a + len, peo[i].r) - a;
    peo[i].b = upper_bound(a, a + len, peo[i].b) - a;
  }
  sort(bus, bus + n);
  sort(peo, peo + m);
  int Max = len;
  build(1, len, 1);
  cnt = 0;
  for (int i = 0; i < m; i++) {
    while (cnt < n && bus[cnt].s <= peo[i].l) {
      update(bus[cnt].t, bus[cnt].f, 1, Max, 1);
      cnt++;
    }
    int ans = query(peo[i].b, Max, peo[i].r, 1, Max, 1);
    if (ans == -1)
      peo[i].ans = -1;
    else
      peo[i].ans = T[ans];
  }
  sort(peo, peo + m, cmp);
  for (int i = 0; i < m; i++) {
    printf("%d%c", peo[i].ans, i == m - 1 ? '\n' : ' ');
  }
  return 0;
}
