#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
inline int sign(double x) { return (x > eps) - (x < -eps); }
const int maxn = 3e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
vector<int> d;
inline int hs(int x) {
  return lower_bound(d.begin(), d.end(), x) - d.begin() + 1;
}
pair<int, int> mx[maxn << 2];
void build(int l, int r, int rt) {
  mx[rt] = make_pair(0, -1);
  if (l == r) return;
  int m = l + r >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
}
void upd(int p, pair<int, int> c, int l, int r, int rt) {
  if (l == r) {
    mx[rt] = max(mx[rt], c);
    return;
  }
  int m = l + r >> 1;
  if (p <= m)
    upd(p, c, l, m, rt << 1);
  else
    upd(p, c, m + 1, r, rt << 1 | 1);
  mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]);
}
pair<int, int> qry(int b, int L, int R, int l, int r, int rt) {
  if (l == r) return mx[rt].first >= b ? mx[rt] : make_pair(0, -1);
  int m = l + r >> 1;
  pair<int, int> res = make_pair(0, -1);
  if (L <= m && mx[rt << 1].first >= b)
    res = max(res, qry(b, L, R, l, m, rt << 1));
  if (R > m && res.second == -1 && mx[rt << 1 | 1].first >= b)
    res = max(res, qry(b, L, R, m + 1, r, rt << 1 | 1));
  return res;
}
struct node {
  int l, r, t, id;
  bool operator<(const node& a) const { return l < a.l; }
};
node a[maxn], b[maxn];
int ans[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].t);
    a[i].id = i;
    d.push_back(a[i].t);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &b[i].l, &b[i].r, &b[i].t);
    b[i].id = i;
    d.push_back(b[i].t);
  }
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  build(1, int(d.size()), 1);
  for (int i = 1, j = 1; i <= m; ++i) {
    while (j <= n && a[j].l <= b[i].l)
      upd(hs(a[j].t), make_pair(a[j].r, a[j].id), 1, int(d.size()), 1), ++j;
    ans[b[i].id] =
        qry(b[i].r, hs(b[i].t), int(d.size()), 1, int(d.size()), 1).second;
  }
  for (int i = 1; i <= m; ++i) printf("%d%c", ans[i], " \n"[i == m]);
  return 0;
}
