#include <bits/stdc++.h>
using namespace std;
constexpr int64_t INF = 1e18;
int64_t solve(int n, int m, const vector<int64_t>& a, const vector<int64_t>& b,
              const vector<int64_t>& c, const vector<int64_t>& d,
              const vector<int64_t>& e, const vector<int64_t>& f) {
  vector<int64_t> ys;
  ys.insert(ys.end(), ::std::begin(c), ::std::end(c));
  ys.insert(ys.end(), ::std::begin(e), ::std::end(e));
  ys.insert(ys.end(), ::std::begin(f), ::std::end(f));
  ys.push_back(INF);
  ys.push_back(-INF);
  sort(::std::begin(ys), ::std::end(ys));
  ys.erase(unique(::std::begin(ys), ::std::end(ys)), ys.end());
  vector<int64_t> xs;
  xs.insert(xs.end(), ::std::begin(a), ::std::end(a));
  xs.insert(xs.end(), ::std::begin(b), ::std::end(b));
  xs.insert(xs.end(), ::std::begin(d), ::std::end(d));
  xs.push_back(INF);
  xs.push_back(-INF);
  sort(::std::begin(xs), ::std::end(xs));
  xs.erase(unique(::std::begin(xs), ::std::end(xs)), xs.end());
  int h = ys.size() - 1;
  int w = xs.size() - 1;
  vector<vector<char> > dist(2 * h - 1, vector<char>(2 * w - 1, '.'));
  for (int i = 0; (i) < (int)(n); ++(i)) {
    int a_i =
        (lower_bound(::std::begin(xs), ::std::end(xs), a[i]) - xs.begin()) * 2 -
        1;
    int b_i =
        (lower_bound(::std::begin(xs), ::std::end(xs), b[i]) - xs.begin()) * 2 -
        1;
    int c_i =
        (lower_bound(::std::begin(ys), ::std::end(ys), c[i]) - ys.begin()) * 2 -
        1;
    for (int x = (a_i); (x) < (int)(b_i + 1); ++(x)) {
      dist[c_i][x] = '#';
    }
  }
  for (int i = 0; (i) < (int)(m); ++(i)) {
    int d_i =
        (lower_bound(::std::begin(xs), ::std::end(xs), d[i]) - xs.begin()) * 2 -
        1;
    int e_i =
        (lower_bound(::std::begin(ys), ::std::end(ys), e[i]) - ys.begin()) * 2 -
        1;
    int f_i =
        (lower_bound(::std::begin(ys), ::std::end(ys), f[i]) - ys.begin()) * 2 -
        1;
    for (int y = (e_i); (y) < (int)(f_i + 1); ++(y)) {
      dist[y][d_i] = '#';
    }
  }
  stack<pair<int, int> > stk;
  int y =
      (lower_bound(::std::begin(ys), ::std::end(ys), 0) - ys.begin()) * 2 - 1;
  int x =
      (lower_bound(::std::begin(xs), ::std::end(xs), 0) - xs.begin()) * 2 - 1;
  dist[y][x] = '*';
  stk.emplace(y, x);
  while (not stk.empty()) {
    auto [y, x] = stk.top();
    stk.pop();
    for (int i = 0; (i) < (int)(4); ++(i)) {
      int ny = y + (i - 2) % 2;
      int nx = x + (i - 1) % 2;
      if (ny < 0 or 2 * h - 1 <= ny or nx < 0 or 2 * w - 1 <= nx) {
        return INF;
      }
      if (dist[ny][nx] == '.') {
        dist[ny][nx] = '*';
        stk.emplace(ny, nx);
      }
    }
  }
  int64_t ans = 0;
  for (int y = 0; (y) < (int)(2 * h - 1); ++(y))
    if (y % 2 == 0) {
      for (int x = 0; (x) < (int)(2 * w - 1); ++(x))
        if (x % 2 == 0 and dist[y][x] == '*') {
          int64_t dy = ys[y / 2 + 1] - ys[y / 2];
          int64_t dx = xs[x / 2 + 1] - xs[x / 2];
          ans += dy * dx;
        }
    }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  constexpr char endl = '\n';
  int N, M;
  cin >> N;
  vector<int64_t> A(N), B(N), C(N);
  cin >> M;
  vector<int64_t> D(M), E(M), F(M);
  for (int i = 0; (i) < (int)(N); ++(i)) {
    cin >> A[i] >> B[i] >> C[i];
  }
  for (int i = 0; (i) < (int)(M); ++(i)) {
    cin >> D[i] >> E[i] >> F[i];
  }
  auto ans = solve(N, M, A, B, C, D, E, F);
  if (ans == INF) {
    cout << "INF" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
