#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10, M = 3e6 + 10, INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N], n, m, in[N], out[N], idx, rnk[N];
vector<int> g[N];
int gcd(int a, int b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
struct node {
  int L[N << 2], R[N << 2], maxx[N << 2], tag[N << 2], ID[N << 2];
  void push_up(int u) { maxx[u] = max(maxx[u << 1], maxx[u << 1 | 1]); }
  void build(int u, int l, int r) {
    L[u] = l, R[u] = r;
    if (l == r) return;
    int mid = l + r >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
    push_up(u);
  }
  void update(int u, int pos, int val, int id) {
    if (L[u] == R[u]) {
      maxx[u] = max(maxx[u], val);
      ID[u] = id;
      return;
    }
    int mid = L[u] + R[u] >> 1;
    if (pos <= mid)
      update(u << 1, pos, val, id);
    else
      update(u << 1 | 1, pos, val, id);
    push_up(u);
  }
  int querymax(int u, int ql, int qr) {
    if (ql <= L[u] && qr >= R[u]) return maxx[u];
    int mid = L[u] + R[u] >> 1;
    int Max = 0;
    if (ql <= mid) Max = max(Max, querymax(u << 1, ql, qr));
    if (qr > mid) Max = max(Max, querymax(u << 1 | 1, ql, qr));
    return Max;
  }
  int query(int u, int val, int pos) {
    if (maxx[u] < val) return -1;
    if (L[u] == R[u]) return ID[u];
    int mid = L[u] + R[u] >> 1;
    if (mid >= pos) {
      int tmp = query(u << 1, val, pos);
      if (tmp > 0) return tmp;
    }
    return query(u << 1 | 1, val, pos);
  }
} st;
struct Q {
  int l, r, t;
  int id;
  bool operator<(const Q &rhs) const {
    if (l == rhs.l) return id < rhs.id;
    return l < rhs.l;
  }
} bus[N], people[N], q[N];
vector<int> ve;
int ans[N];
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> bus[i].l >> bus[i].r >> bus[i].t;
    ve.push_back(bus[i].t);
    bus[i].id = i;
    q[i] = bus[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> people[i].l >> people[i].r >> people[i].t;
    ve.push_back(people[i].t);
    people[i].id = i + n;
    q[i + n] = people[i];
  }
  sort(ve.begin(), ve.end());
  ve.erase(unique(ve.begin(), ve.end()), ve.end());
  sort(q + 1, q + n + m + 1);
  st.build(1, 1, n + m);
  for (int i = 1; i <= n + m; i++) {
    int t = lower_bound(ve.begin(), ve.end(), q[i].t) - ve.begin() + 1;
    if (q[i].id <= n) {
      st.update(1, t, q[i].r, q[i].id);
    } else {
      ans[q[i].id - n] = st.query(1, q[i].r, t);
    }
  }
  for (int i = 1; i <= m; i++) printf("%d ", ans[i]);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
