#include <bits/stdc++.h>
using namespace std;
struct Segment {
  int R, id;
} T[100005 << 3];
struct Bus {
  int s, f, t;
  int id;
  bool operator<(const Bus& x) const {
    if (s != x.s) return s < x.s;
    return f < x.f;
  }
} bus[100005];
struct People {
  int l, r, b;
  int id;
  bool operator<(const People& x) const {
    if (l != x.l) return l < x.l;
    return r < x.r;
  }
} people[100005];
int tp[100005 << 1];
int n, m;
int cnt;
int ans[100005];
int Cal(int x) {
  int l, r, mid;
  l = 0, r = cnt - 1;
  while (l < r) {
    mid = (l + r) >> 1;
    if (tp[mid] < x)
      l = mid + 1;
    else
      r = mid;
  }
  return l;
}
void Up(int i) { T[i].R = max(T[i << 1].R, T[i << 1 | 1].R); }
void Build(int i, int l, int r) {
  if (l == r) {
    T[i].R = -1;
    return;
  }
  int mid = (l + r) >> 1;
  Build(i << 1, l, mid);
  Build(i << 1 | 1, mid + 1, r);
  Up(i);
}
void Insert(int i, int l, int r, int x, int rr, int id) {
  if (l == r) {
    if (T[i].R < rr) {
      T[i].R = rr;
      T[i].id = id;
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    Insert(i << 1, l, mid, x, rr, id);
  else
    Insert(i << 1 | 1, mid + 1, r, x, rr, id);
  Up(i);
}
int Query(int i, int l, int r, int ll, int rr, int x) {
  if (T[i].R < x) return -1;
  if (l == r) {
    return T[i].id;
  }
  int mid = (l + r) >> 1;
  int ans = -2;
  if (ll <= mid) ans = Query(i << 1, l, mid, ll, rr, x);
  if (ans > 0) return ans;
  if (rr > mid) ans = Query(i << 1 | 1, mid + 1, r, ll, rr, x);
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  cnt = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &bus[i].s, &bus[i].f, &bus[i].t);
    bus[i].id = i + 1;
    tp[cnt++] = bus[i].t;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &people[i].l, &people[i].r, &people[i].b);
    people[i].id = i + 1;
    tp[cnt++] = people[i].b;
  }
  int j = 1;
  sort(tp, tp + cnt);
  for (int i = 1; i < cnt; i++) {
    if (tp[i] != tp[i - 1]) tp[j++] = tp[i];
  }
  cnt = j;
  Build(1, 0, cnt - 1);
  sort(bus, bus + n);
  sort(people, people + m);
  int i;
  i = j = 0;
  while (i < m) {
    while (j < n && bus[j].s <= people[i].l) {
      int k = Cal(bus[j].t);
      Insert(1, 0, cnt - 1, k, bus[j].f, bus[j].id);
      j++;
    }
    int k = Cal(people[i].b);
    ans[people[i].id] = Query(1, 0, cnt - 1, k, cnt - 1, people[i].r);
    i++;
  }
  for (int i = 1; i <= m; i++) {
    if (i > 1) printf(" ");
    printf("%d", ans[i]);
  }
  puts("");
  return 0;
}
