#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int a, it, b, c, cn, ans[200007], d[200007], w, n, m;
pair<pair<int, int>, pair<int, int> > q[200007], p[200007];
map<int, int> mk;
pair<int, int> T[200007 << 2];
void upd(int x, int y, int z, int l, int r, int v) {
  if (l == r) {
    if (y > T[v].first) T[v] = {y, z};
    return;
  }
  if (x <= (l + r) / 2)
    upd(x, y, z, l, (l + r) / 2, v << 1);
  else
    upd(x, y, z, (l + r) / 2 + 1, r, v << 1 | 1);
  if (T[v << 1].first >= T[v << 1 | 1].first)
    T[v] = T[v << 1];
  else
    T[v] = T[v << 1 | 1];
}
pair<int, int> bul(int x, int y, int z, int l, int r, int v) {
  if (T[v].first < z) return {0, 0};
  if (y < l || r < x) return {0, 0};
  if (l == r) return T[v];
  pair<int, int> t1 = bul(x, y, z, l, (l + r) / 2, v << 1);
  if (t1.first > 0) return t1;
  pair<int, int> t2 = bul(x, y, z, (l + r) / 2 + 1, r, v << 1 | 1);
  return t2;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    p[i] = {{a, b}, {c, i}};
    mk[c] = 1;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    q[i] = {{a, b}, {c, i}};
    mk[c] = 1;
  }
  for (__typeof((mk).begin()) i = (mk).begin(); i != (mk).end(); i++)
    i->second = ++cn;
  for (int i = 1; i <= n; i++) p[i].second.first = mk[p[i].second.first];
  for (int i = 1; i <= m; i++) q[i].second.first = mk[q[i].second.first];
  sort(p + 1, p + n + 1);
  sort(q + 1, q + m + 1);
  it = 1;
  for (int i = 1; i <= m; i++) {
    a = q[i].first.first, b = q[i].first.second, c = q[i].second.first,
    w = q[i].second.second;
    while (it <= n && p[it].first.first <= a)
      upd(p[it].second.first, p[it].first.second, p[it].second.second, 1, cn,
          1),
          it++;
    ans[w] = bul(c, cn, b, 1, cn, 1).second;
  }
  for (int i = 1; i <= m; i++) printf("%d ", (!ans[i] ? -1 : ans[i]));
  puts("");
  return 0;
}
