#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;
const int INF = 0x3f3f3f3f;
int ans[N];
int n;
struct node {
  int low, high, max_end;
  int id;
} tree[N * 4];
struct Bus {
  int id, start, end, time;
  bool operator<(const Bus &w) const {
    if (start == w.start) return id < w.id;
    return start < w.start;
  }
} bus[N];
void build(int k, int low, int high) {
  tree[k].low = low;
  tree[k].high = high;
  if (low == high) {
    tree[k].max_end = -1;
    return;
  }
  int mid, l_ch, r_ch;
  mid = tree[k].low + tree[k].high >> 1;
  build(2 * k, low, mid);
  build(2 * k + 1, mid + 1, high);
}
void pushup(int k) {
  tree[k].max_end = max(tree[2 * k].max_end, tree[2 * k + 1].max_end);
}
void update(int k, int i, int v, int id) {
  if (tree[k].low == tree[k].high && tree[k].low == i) {
    tree[k].max_end = v;
    tree[k].id = id;
    return;
  }
  int mid = (tree[k].low + tree[k].high) >> 1;
  if (i <= mid)
    update(2 * k, i, v, id);
  else {
    update(2 * k + 1, i, v, id);
  }
  pushup(k);
}
int q_max(int k, int val, int low, int high) {
  if (tree[k].low >= low && tree[k].high <= high) {
    if (tree[k].max_end < val) {
      return -1;
    }
  }
  if (tree[k].low == tree[k].high) {
    return tree[k].id;
  }
  int mid = tree[k].low + tree[k].high >> 1;
  int ans;
  if (low <= mid) {
    int t = q_max(2 * k, val, low, high);
    if (t != -1) {
      return t;
    }
  }
  if (high >= mid + 1) {
    int t = q_max(2 * k + 1, val, low, high);
    if (t != -1) {
      return t;
    }
  }
  return -1;
}
int Hash[N];
int idx = 1;
int main() {
  int low, high;
  int i, v;
  int numbus, numman;
  scanf("%d%d", &numbus, &numman);
  int total = numbus + numman;
  for (int i = 1; i <= total; i++) {
    scanf("%d%d%d", &bus[i].start, &bus[i].end, &bus[i].time);
    bus[i].id = i;
    Hash[idx++] = bus[i].time;
  }
  sort(bus + 1, bus + 1 + total);
  sort(Hash + 1, Hash + 1 + total);
  int d = unique(Hash + 1, Hash + 1 + total) - (Hash + 1);
  build(1, 1, d);
  for (int i = 1; i <= total; i++) {
    if (bus[i].id <= numbus) {
      int pos = lower_bound(Hash + 1, Hash + 1 + d, bus[i].time) - Hash;
      update(1, pos, bus[i].end, bus[i].id);
    }
    if (bus[i].id > numbus) {
      int pos = lower_bound(Hash + 1, Hash + 1 + d, bus[i].time) - Hash;
      ans[bus[i].id - numbus] = q_max(1, bus[i].end, pos, d);
    }
  }
  for (int i = 1; i <= numman; i++) {
    cout << ans[i] << " ";
  }
}
