#include <bits/stdc++.h>
using namespace std;
const long long lnf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 201000;
const int mod = 1e9 + 7;
struct node {
  int l, r;
  int rmax;
  int id;
} t[maxn << 2];
struct nn {
  int flag;
  int li, ri, ti;
  int id;
  nn() {}
  nn(int a, int b, int c, int d, int e) {
    flag = a, li = b, ri = c, ti = d, id = e;
  }
  friend bool operator<(const nn& a, const nn& b) {
    if (a.li != b.li)
      return a.li < b.li;
    else
      return a.flag < b.flag;
  }
} b[maxn];
int a[maxn];
int ans[maxn];
void pushup(int cnt) {
  if (t[cnt << 1].rmax >= t[cnt << 1 | 1].rmax)
    t[cnt].rmax = t[cnt << 1].rmax, t[cnt].id = t[cnt << 1].id;
  else
    t[cnt].rmax = t[cnt << 1 | 1].rmax, t[cnt].id = t[cnt << 1 | 1].id;
}
void build(int l, int r, int cnt) {
  t[cnt].l = l, t[cnt].r = r;
  t[cnt].rmax = -1;
  t[cnt].id = -1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid, cnt << 1);
  build(mid + 1, r, cnt << 1 | 1);
}
void change(int pos, int rmm, int id, int cnt) {
  if (t[cnt].l == t[cnt].r) {
    t[cnt].rmax = rmm;
    t[cnt].id = id;
    return;
  }
  if (pos <= t[cnt << 1].r)
    change(pos, rmm, id, cnt << 1);
  else
    change(pos, rmm, id, cnt << 1 | 1);
  pushup(cnt);
}
int ask(int l, int r, int rmm, int cnt) {
  if (t[cnt].rmax < rmm) return -1;
  if (t[cnt].l == t[cnt].r && t[cnt].rmax >= rmm)
    return t[cnt].id;
  else if (t[cnt].l == t[cnt].r)
    return -1;
  if (l <= t[cnt].l && t[cnt].r <= r) {
    if (t[cnt << 1].rmax >= rmm)
      return ask(l, r, rmm, cnt << 1);
    else if (t[cnt << 1 | 1].rmax >= rmm)
      return ask(l, r, rmm, cnt << 1 | 1);
    else
      return -1;
  }
  int ans = -1;
  if (l <= t[cnt << 1].r && rmm <= t[cnt << 1].rmax)
    ans = ask(l, r, rmm, cnt << 1);
  if (ans == -1)
    if (r >= t[cnt << 1 | 1].r && rmm <= t[cnt << 1 | 1].rmax)
      ans = ask(l, r, rmm, cnt << 1 | 1);
  return ans;
}
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  int l, r, ti;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &l, &r, &ti);
    ++cnt;
    b[cnt] = nn(0, l, r, ti, i);
    a[cnt] = ti;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &l, &r, &ti);
    ++cnt;
    b[cnt] = nn(1, l, r, ti, i);
    a[cnt] = ti;
  }
  sort(b + 1, b + cnt + 1);
  sort(a + 1, a + cnt + 1);
  int pm = cnt;
  cnt = unique(a + 1, a + cnt + 1) - (a + 1);
  build(1, cnt, 1);
  for (int i = 1; i <= pm; i++) {
    if (b[i].flag == 0)
      change(lower_bound(a + 1, a + cnt + 1, b[i].ti) - a, b[i].ri, b[i].id, 1);
    else if (b[i].flag) {
      ans[b[i].id] =
          ask(lower_bound(a + 1, a + cnt + 1, b[i].ti) - a, cnt, b[i].ri, 1);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (i != 1) putchar(' ');
    printf("%d", ans[i]);
    if (i == m) putchar('\n');
  }
  return 0;
}
