#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 * 4 + 152, inf = 1e9 + 152;
int n, m, x, y, z, par[maxn], ans[maxn], pos;
vector<pair<pair<int, int>, pair<int, int> > > v;
set<pair<int, int> > st[maxn];
bool jack;
void update(int x, int val, int lo = 1, int hi = 2 * (n + m), int curr = 1) {
  if (x < lo || hi < x) return;
  if (!jack)
    st[curr].insert(make_pair(val, pos));
  else {
    set<pair<int, int> >::iterator it = st[curr].find(make_pair(val, pos));
    st[curr].erase(it);
  }
  if (lo == hi) return;
  int mid = (lo + hi) / 2;
  update(x, val, lo, mid, curr * 2);
  update(x, val, mid + 1, hi, curr * 2 + 1);
}
pair<int, int> find_ans(int x, int val, int lo = 1, int hi = 2 * (n + m),
                        int curr = 1) {
  if (x < lo) return make_pair(inf, -1);
  if (hi <= x) {
    set<pair<int, int> >::iterator it = st[curr].lower_bound(make_pair(val, 0));
    if (it == st[curr].end()) return make_pair(inf, -1);
    return *it;
  }
  int mid = (lo + hi) / 2;
  pair<int, int> a = find_ans(x, val, lo, mid, curr * 2),
                 b = find_ans(x, val, mid + 1, hi, curr * 2 + 1);
  if (a.first < b.first) return a;
  return b;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    v.push_back(make_pair(make_pair(x, 0), make_pair(z, i)));
    v.push_back(make_pair(make_pair(y, 3), make_pair(z, i)));
  }
  for (int i = n; i < n + m; i++) {
    cin >> x >> y >> z;
    v.push_back(make_pair(make_pair(x, 1), make_pair(z, i)));
    v.push_back(make_pair(make_pair(y, 2), make_pair(z, i)));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (v[i].first.second == 0) {
      jack = 0, pos = v[i].second.second + 1;
      update(i + 1, v[i].second.first);
      par[v[i].second.second] = i + 1;
    }
    if (v[i].first.second == 3) {
      jack = 1, pos = v[i].second.second + 1;
      update(par[v[i].second.second], v[i].second.first);
    }
    if (v[i].first.second == 1) par[v[i].second.second] = i + 1;
    if (v[i].first.second == 2)
      ans[v[i].second.second - n] =
          find_ans(par[v[i].second.second], v[i].second.first).second;
  }
  for (int i = 0; i < m; i++) cout << ans[i] << "\n";
  return 0;
}
