#include <bits/stdc++.h>
using namespace std;
int N, M;
int KD[200010 * 3], tpos[200010];
pair<int, int> srt[200010], bus[200010];
pair<pair<int, int>, pair<int, int> > event[200010];
pair<pair<int, int>, int> tmp[200010];
map<int, int> pos;
map<pair<pair<int, int>, int>, int> last;
bool comp(const pair<pair<int, int>, pair<int, int> > &a,
          const pair<pair<int, int>, pair<int, int> > &b) {
  if (a.first.first != b.first.first) return a.first.first < b.first.first;
  return a.second.second < b.second.second;
}
void update(int k, int s, int e, int id) {
  if (bus[id].first > e || bus[id].first < s) return;
  if (s == e) {
    KD[k] = id;
    return;
  }
  update(2 * k, s, (s + e) / 2, id);
  update(2 * k + 1, (s + e) / 2 + 1, e, id);
  if (bus[KD[2 * k]].second > bus[KD[2 * k + 1]].second)
    KD[k] = KD[2 * k];
  else
    KD[k] = KD[2 * k + 1];
}
int find(int k, int s, int e, int p, int val) {
  if (p > e) return -1;
  if (bus[KD[k]].second < val) return -1;
  if (s == e) return KD[k];
  int rv = find(2 * k, s, (s + e) / 2, p, val);
  if (rv != -1) return rv;
  return find(2 * k + 1, (s + e) / 2 + 1, e, p, val);
}
int main() {
  int i, t;
  scanf(" %d %d", &N, &M);
  for (i = 1; i <= N; i++) {
    scanf(" %d %d %d", &event[i].first.first, &event[i].first.second,
          &event[i].second.first);
    bus[i].second = event[i].first.second;
    event[i].second.second = 0;
    srt[i] = pair<int, int>(event[i].second.first, i);
  }
  for (i = N + 1; i <= N + M; i++) {
    scanf(" %d %d %d", &event[i].first.first, &event[i].first.second,
          &event[i].second.first);
    event[i].second.second = 1;
    tmp[i - N] = pair<pair<int, int>, int>(
        pair<int, int>(event[i].first.first, event[i].first.second),
        event[i].second.first);
  }
  sort(event + 1, event + N + M + 1, comp);
  sort(srt + 1, srt + N + 1);
  for (i = 1; i <= N; i++) bus[srt[i].second].first = i;
  srt[N + 1] = pair<int, int>(2000000000, 1);
  for (i = 1; i <= N; i++) pos[srt[i].first] = srt[i].second;
  for (i = 1; i <= N + M; i++)
    if (event[i].second.second) {
      t = lower_bound(srt + 1, srt + N + 1,
                      pair<int, int>(event[i].second.first, 0)) -
          srt;
      if (t > N) {
        last[pair<pair<int, int>, int>(
            pair<int, int>(event[i].first.first, event[i].first.second),
            event[i].second.first)] = -1;
        continue;
      }
      last[pair<pair<int, int>, int>(
          pair<int, int>(event[i].first.first, event[i].first.second),
          event[i].second.first)] = find(1, 1, N, t, event[i].first.second);
    } else
      update(1, 1, N, pos[event[i].second.first]);
  for (i = 1; i <= M; i++) printf("%d ", last[tmp[i]]);
  printf("\n");
  return 0;
}
