#include <bits/stdc++.h>
using namespace std;
const int K = 333;
int n, m;
const int N = 100000;
struct T {
  int st, fn, when, tp, add;
};
inline bool sort_time(const T& a, const T& b) {
  if (a.when != b.when) return a.when < b.when;
  return a.tp < b.tp;
}
inline bool sort_segm(const T& a, const T& b) {
  return make_pair(a.st, a.fn) < make_pair(b.st, b.fn);
}
inline bool operator<(const T& a, const T& b) {
  if (a.fn != b.fn) return a.fn > b.fn;
  return a.add < b.add;
}
T seg[N], que[N];
set<T> best;
int ans[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", &seg[i].st, &seg[i].fn, &seg[i].when);
    seg[i].tp = i;
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &que[i].st, &que[i].fn, &que[i].when);
    que[i].tp = i;
  }
  memset(ans, -1, sizeof(ans));
  sort(seg, seg + n, sort_time);
  sort(que, que + m, sort_segm);
  int old_m = m;
  for (int beg = 0; beg < n;) {
    vector<T> ev(0);
    int end = beg;
    while (end < n && end - beg < K) {
      T el;
      el = seg[end];
      el.when = seg[end].st;
      el.tp = 1;
      el.add = seg[end].tp;
      ev.push_back(el);
      el = seg[end];
      el.when = seg[end].fn + 1;
      el.tp = 0;
      el.add = seg[end].tp;
      ev.push_back(el);
      end++;
    }
    sort((ev).begin(), (ev).end(), sort_time);
    best.clear();
    vector<T> possible(0);
    int pos = 0;
    for (int i = 0; i < m; ++i) {
      while (pos < (int)(ev).size() && ev[pos].when <= que[i].st) {
        if (ev[pos].tp == 1) {
          best.insert(ev[pos]);
        } else {
          best.erase(best.find(ev[pos]));
        }
        ++pos;
      }
      if ((int)(best).size() && best.begin()->fn >= que[i].fn &&
          que[i].when <= seg[end - 1].when) {
        possible.push_back(que[i]);
      }
    }
    while (beg < end) {
      for (int i = 0; i < (int)(possible).size(); ++i) {
        if (seg[beg].st <= possible[i].st && seg[beg].fn >= possible[i].fn &&
            possible[i].when <= seg[beg].when) {
          if (ans[possible[i].tp] != -1) continue;
          ans[possible[i].tp] = seg[beg].tp + 1;
        }
      }
      ++beg;
    }
    int newm = 0;
    for (int i = 0; i < m; ++i) {
      if (ans[que[i].tp] == -1) {
        que[newm++] = que[i];
      }
    }
    m = newm;
  }
  for (int i = 0; i < old_m; ++i) {
    if (i) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}
