#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int, int>;
using vb = vector<bool>;
const int INF = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, vector<P> > xmp, ymp;
  for (int i = 0; i < (n); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    ymp[c].emplace_back(a, b);
  }
  for (int i = 0; i < (m); ++i) {
    int a, b, c;
    cin >> c >> a >> b;
    xmp[c].emplace_back(a, b);
  }
  vec xs, ys;
  for (auto pp : xmp) {
    xs.push_back(pp.first);
  }
  sort((xs).begin(), (xs).end());
  for (auto pp : ymp) {
    ys.push_back(pp.first);
  }
  sort((ys).begin(), (ys).end());
  vector<vb> xb(xs.size(), vb(ys.size(), false)),
      yb(xs.size(), vb(ys.size(), false));
  for (int x = 0; x < (xs.size()); ++x) {
    int k = 0;
    vector<P> v = xmp[xs[x]];
    sort((v).begin(), (v).end());
    for (int y = 0; y < (ys.size()); ++y) {
      while (k < v.size() && ys[y] >= v[k].second) k++;
      if (k == v.size()) break;
      cout << ys[y] << v[k].first << v[k].second << endl;
      if (ys[y] >= v[k].first && ys[y] < v[k].second) xb[x][y] = true;
    }
  }
  for (int y = 0; y < (ys.size()); ++y) {
    int k = 0;
    vector<P> v = ymp[ys[y]];
    sort((v).begin(), (v).end());
    for (int x = 0; x < (xs.size()); ++x) {
      while (k < v.size() && xs[x] >= v[k].second) k++;
      if (k == v.size()) break;
      cout << ys[y] << v[k].first << v[k].second << endl;
      if (xs[x] >= v[k].first && xs[x] < v[k].second) yb[x][y] = true;
    }
  }
  for (int y = 0; y < (ys.size() - 1); ++y) {
    cout << (xb[0][y] ? " _" : "  ");
  }
  cout << endl;
  for (int x = 0; x < (xs.size() - 1); ++x) {
    for (int y = 0; y < (ys.size() - 1); ++y) {
      cout << (yb[x][y] ? "|" : " ");
      cout << (xb[x + 1][y] ? "_" : " ");
    }
    cout << (yb[x + 1][ys.size() - 1] ? "|" : " ") << endl;
  }
  queue<P> que;
  vector<vb> flag(xs.size() - 1, vb(ys.size() - 1));
  int sx = upper_bound((xs).begin(), (xs).end(), 0) - xs.begin() - 1;
  int sy = upper_bound((ys).begin(), (ys).end(), 0) - ys.begin() - 1;
  if (sx < 0 || sy < 0) {
    cout << "INF" << endl;
    return 0;
  }
  que.push(P(sx, sy));
  flag[sx][sy] = true;
  int sum = (xs[sx + 1] - xs[sx]) * (ys[sy + 1] - ys[sy]);
  while (que.size()) {
    P p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    vector<P> next;
    if (!xb[x][y]) next.push_back(P(x - 1, y));
    if (!xb[x + 1][y]) next.push_back(P(x + 1, y));
    if (!yb[x][y]) next.push_back(P(x, y - 1));
    if (!yb[x][y + 1]) next.push_back(P(x, y + 1));
    for (P np : next) {
      int nx = np.first, ny = np.second;
      if (nx == -1 || nx == xs.size() - 1 || ny == -1 || ny == ys.size() - 1) {
        cout << "INF" << endl;
        return 0;
      }
      if (!flag[nx][ny]) {
        que.push(np);
        flag[nx][ny] = true;
        sum += (xs[nx + 1] - xs[nx]) * (ys[ny + 1] - ys[ny]);
      }
    }
  }
  cout << sum << endl;
  return 0;
}
