#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(n), c(n);
  vector<long long> old_x(2 * n + m);
  vector<long long> old_y(n + 2 * m);
  for (long long i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    old_x[2 * i] = a[i];
    old_x[2 * i + 1] = b[i];
    old_y[i] = c[i];
  }
  vector<long long> d(m), e(m), f(m);
  for (long long i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    old_x[2 * n + i] = d[i];
    old_y[n + 2 * i] = e[i];
    old_y[n + 2 * i + 1] = f[i];
  }
  sort(old_x.begin(), old_x.end());
  old_x.erase(unique(old_x.begin(), old_x.end()), old_x.end());
  sort(old_y.begin(), old_y.end());
  old_y.erase(unique(old_y.begin(), old_y.end()), old_y.end());
  map<long long, long long> new_x, new_y;
  for (long long i = 0; i < old_x.size(); i++) {
    new_x[old_x[i]] = i;
  }
  for (long long i = 0; i < old_y.size(); i++) {
    new_y[old_y[i]] = i;
  }
  vector<vector<long long>> ver_edge(old_x.size() + 2,
                                     vector<long long>(old_y.size() + 2, 1));
  vector<vector<long long>> hor_edge(old_x.size() + 2,
                                     vector<long long>(old_y.size() + 2, 1));
  for (long long i = 0; i < n; i++) {
    long long new_j = new_y[c[i]];
    for (long long new_i = new_x[a[i]]; new_i < new_x[b[i]]; new_i++) {
      ver_edge[new_i + 1][new_j] = 0;
    }
  }
  for (long long i = 0; i < m; i++) {
    long long new_i = new_x[d[i]];
    for (long long new_j = new_y[e[i]]; new_j < new_y[f[i]]; new_j++) {
      hor_edge[new_i][new_j + 1] = 0;
    }
  }
  vector<vector<long long>> visited(old_x.size() + 2,
                                    vector<long long>(old_y.size() + 2, 0));
  auto itrx_l = lower_bound(old_x.begin(), old_x.end(), 0);
  auto itrx_u = upper_bound(old_x.begin(), old_x.end(), 0);
  long long i_l = distance(old_x.begin(), itrx_l);
  long long i_u = distance(old_x.begin(), itrx_u);
  if (i_l == 0 || i_u >= old_x.size() - 1) {
    cout << "INF" << endl;
    return 0;
  }
  auto itry_l = lower_bound(old_y.begin(), old_y.end(), 0);
  auto itry_u = upper_bound(old_y.begin(), old_y.end(), 0);
  long long j_l = distance(old_y.begin(), itry_l);
  long long j_u = distance(old_y.begin(), itry_u);
  if (j_l == 0 || j_u >= old_y.size() - 1) {
    cout << "INF" << endl;
    return 0;
  }
  queue<long long> qi;
  queue<long long> qj;
  for (long long i = i_l; i <= i_u; i++) {
    for (long long j = j_l; j <= j_u; j++) {
      qi.push(i);
      qj.push(j);
      visited[i][j] = 1;
    }
  }
  auto is_around = [&](long long i, long long j) {
    return i == 0 || i == old_x.size() + 2 || j == 0 || j == old_y.size() + 2;
  };
  while (!qi.empty()) {
    long long nowi = qi.front();
    long long nowj = qj.front();
    qi.pop();
    qj.pop();
    long long di[4] = {0, 0, 1, -1};
    long long dj[4] = {1, -1, 0, 0};
    for (long long k = 0; k < 4; k++) {
      long long nexti = nowi + di[k];
      long long nextj = nowj + dj[k];
      if (visited[nexti][nextj] != 0) continue;
      if ((di[k] == 0 && ver_edge[nowi][nowj + (dj[k] - 1) / 2]) == 1 ||
          (dj[k] == 0 && hor_edge[nowi + (di[k] - 1) / 2][nowj] == 1)) {
        if (is_around(nexti, nextj)) {
          cout << "INF" << endl;
          return 0;
        }
        visited[nexti][nextj] = 1;
        qi.push(nexti);
        qj.push(nextj);
      }
    }
  }
  long long area = 0;
  for (long long i = 0; i < old_x.size() - 1; i++) {
    for (long long j = 0; j < old_y.size() - 1; j++) {
      if (visited[i + 1][j + 1] == 1) {
        area += (old_x[i + 1] - old_x[i]) * (old_y[j + 1] - old_y[j]);
      }
    }
  }
  cout << area << endl;
  return 0;
}
