#include <bits/stdc++.h>
using namespace std;
int s[100010], t[100010], f[100010], l[100010], r[100010], b[100010];
int n, m;
map<pair<int, int>, int> t_pos;
map<int, int> t_id;
vector<pair<int, int> > pos;
vector<pair<pair<pair<int, int>, pair<int, int> >, int> > query;
struct tree_t {
  int t, f;
} tree[2 * (1 << 17)];
void update_tree(int t, int f) {
  int p = t_pos[make_pair(t, f)];
  tree[(1 << 17) + p].t = t, tree[(1 << 17) + p].f = f;
  p = (1 << 17) + p;
  while (p > 1) {
    p /= 2;
    tree[p].f = max(tree[2 * p].f, tree[2 * p + 1].f);
    tree[p].t = max(tree[2 * p].t, tree[2 * p + 1].t);
  }
}
int find_tree(int t, int f, int l = 0, int r = n - 1, int id = 1) {
  if (tree[id].f < f || tree[id].t < t) return -1;
  if (id >= (1 << 17)) return t_id[tree[id].t];
  int x = find_tree(t, f, l, (l + r) / 2, id * 2);
  if (x != -1) return x;
  return find_tree(t, f, (l + r) / 2 + 1, r, id * 2 + 1);
}
int res[100010];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &s[i], &f[i], &t[i]);
    query.push_back(
        make_pair(make_pair(make_pair(s[i], 0), make_pair(f[i], t[i])), i));
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &l[i], &r[i], &b[i]);
    query.push_back(
        make_pair(make_pair(make_pair(l[i], 1), make_pair(r[i], b[i])), i));
  }
  for (int i = 0; i < n; i++) {
    pos.push_back(make_pair(t[i], f[i]));
    t_id[t[i]] = i + 1;
  }
  sort(pos.begin(), pos.end());
  for (int i = 0; i < n; i++) t_pos[pos[i]] = i;
  sort(query.begin(), query.end());
  for (int i = 0; i < m + n; i++) {
    if (query[i].first.first.second == 0) {
      update_tree(query[i].first.second.second, query[i].first.second.first);
    } else {
      res[query[i].second] =
          find_tree(query[i].first.second.second, query[i].first.second.first);
    }
  }
  for (int i = 0; i < m; i++) printf("%d ", res[i]);
  printf("\n");
  return 0;
}
