#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 7;
const double INF = 1e12, EPS = 1e-9;
const int MX = 100010;
int n, m, ans[MX];
const int N = 131072;
int dat[2 * N - 1];
inline void update(int k, int x) {
  k += N - 1;
  dat[k] = max(dat[k], x);
  while (k) {
    k = (k - 1) / 2;
    dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}
inline int find(int a, int b, int l, int r, int k, int x) {
  if (b <= l || a >= r) return inf;
  if (dat[k] < x) return inf;
  if (l + 1 == r) return l;
  int t = find(a, b, l, (l + r) / 2, k * 2 + 1, x);
  if (t < inf) return t;
  return find(a, b, (l + r) / 2, r, k * 2 + 2, x);
}
int main() {
  for (int i = 0; i < (int)2 * N - 1; i++) dat[i] = -inf;
  scanf("%d%d", &n, &m);
  vector<pair<pair<int, int>, pair<int, int> > > v;
  vector<int> ts;
  map<int, int> id;
  for (int i = 0; i < (int)n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    v.push_back(make_pair(make_pair(a, i), make_pair(b, c)));
    id[c] = i + 1;
    ts.push_back(c);
  }
  for (int i = 0; i < (int)m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    v.push_back(make_pair(make_pair(a, i + n), make_pair(b, c)));
  }
  sort((v).begin(), (v).end());
  sort((ts).begin(), (ts).end());
  ts.erase(unique((ts).begin(), (ts).end()), ts.end());
  for (int i = 0; i < (int)v.size(); i++) {
    int c =
        lower_bound((ts).begin(), (ts).end(), v[i].second.second) - ts.begin();
    if (v[i].first.second < n) {
      update(c, v[i].second.first);
    } else {
      int k = find(c, N, 0, N, 0, v[i].second.first);
      ans[v[i].first.second - n] = k < inf ? id[ts[k]] : -1;
    }
  }
  for (int i = 0; i < (int)m; i++)
    printf("%d%c", ans[i], i == m - 1 ? '\n' : ' ');
  return 0;
}
