#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MAX_N = 100010;
int l(int x) { return x * 2; }
int r(int x) { return x * 2 + 1; }
struct SegTree {
  struct Node {
    int lb, rb, mid, val, id;
    bool isLeaf() const { return lb == rb; }
  } seg[MAX_N * 6];
  void build(int idx, int s, int e) {
    seg[idx].lb = s, seg[idx].rb = e, seg[idx].id = -1;
    int mid = seg[idx].mid = (s + e) / 2;
    seg[idx].val = INT32_MIN;
    if (s < e) {
      build(l(idx), s, mid);
      build(r(idx), mid + 1, e);
    }
  }
  void update(int idx, int pos, int val, int id) {
    auto& ref = seg[idx];
    if (ref.isLeaf()) {
      ref.val = val, ref.id = id;
      return;
    }
    if (pos <= ref.mid)
      update(l(idx), pos, val, id);
    else
      update(r(idx), pos, val, id);
    ref.val = max(seg[l(idx)].val, seg[r(idx)].val);
  }
  int query(int idx, int stop, int pos) {
    auto& ref = seg[idx];
    if (ref.val < stop) return -1;
    if (ref.isLeaf()) return ref.id;
    if (pos <= ref.mid) {
      int ans = query(l(idx), stop, pos);
      if (ans > 0) return ans;
    }
    return query(r(idx), stop, pos);
  }
} segt;
struct Range {
  int from, to, time, id;
  Range(int f, int t, int i) : from(f), to(t), id(i) {}
  Range() = default;
  bool operator<(const Range& rhs) const {
    return from == rhs.from ? id < rhs.id : from < rhs.from;
  }
  bool isBus() const { return id <= n; }
};
Range arr[2 * MAX_N];
int ans[MAX_N];
int main() {
  scanf("%d %d", &n, &m);
  vector<int> time_set;
  for (int i = 1; i <= n + m; ++i) {
    Range& ref = arr[i];
    scanf("%d %d %d", &ref.from, &ref.to, &ref.time);
    ref.id = i;
    time_set.push_back(ref.time);
  }
  sort(time_set.begin(), time_set.end());
  time_set.erase(unique(time_set.begin(), time_set.end()), time_set.end());
  segt.build(1, 1, time_set.size());
  sort(arr + 1, arr + n + m + 1);
  for (int i = 1; i <= n + m; ++i) {
    auto& ref = arr[i];
    int time_idx = lower_bound(time_set.begin(), time_set.end(), ref.time) -
                   time_set.begin() + 1;
    if (ref.isBus()) {
      segt.update(1, time_idx, ref.to, ref.id);
    } else
      ans[ref.id - n] = segt.query(1, ref.to, time_idx);
  }
  for (int i = 1; i <= m; ++i) printf("%d ", ans[i]);
  return 0;
}
