#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m;
struct node {
  int l, r, time, id;
  bool operator<(const node& a) const {
    return l < a.l || (l == a.l && id < a.id);
  }
} a[maxn];
int b[maxn << 1];
int tree[maxn << 2], cid[maxn];
void push_up(int rt) { tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]); }
void updata(int L, int l, int r, int rt, int val, int id) {
  if (l == r) {
    tree[rt] = max(tree[rt], val);
    cid[l] = id;
    return;
  }
  int mid = l + r >> 1;
  if (L <= mid)
    updata(L, l, mid, rt << 1, val, id);
  else
    updata(L, mid + 1, r, rt << 1 | 1, val, id);
  push_up(rt);
}
int query(int L, int R, int l, int r, int rt, int k) {
  if (tree[rt] < k) return -1;
  if (l == r) {
    if (tree[rt] >= k)
      return cid[l];
    else
      return -1;
  }
  int mid = l + r >> 1;
  int res = -1;
  if (L <= mid) res = query(L, R, l, mid, rt << 1, k);
  if (R > mid && res == -1) res = query(L, R, mid + 1, r, rt << 1 | 1, k);
  return res;
}
int ans[maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n + m; i++) {
    cin >> a[i].l >> a[i].r >> a[i].time;
    a[i].id = i, b[i] = a[i].time;
  }
  sort(b + 1, b + 1 + n + m);
  int cnt = unique(b + 1, b + 1 + n + m) - b - 1;
  sort(a + 1, a + 1 + n + m);
  memset(tree, -1, sizeof tree);
  for (int i = 1; i <= n + m; i++) {
    int pos = lower_bound(b + 1, b + 1 + cnt, a[i].time) - b;
    if (a[i].id <= n) {
      updata(pos, 1, cnt, 1, a[i].r, a[i].id);
    } else {
      ans[a[i].id - n] = query(pos, cnt, 1, cnt, 1, a[i].r);
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
