#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pr = pair<int, int>;
using pir = pair<int, pr>;
using pri = pair<pr, int>;
int N, M, R, C;
pri A[1005];
pir B[1005];
vector<int> cx, cy;
vector<vector<int>> v;
vector<vector<bool>> chk1, chk2;
queue<pr> q;
ll ans;
int xidx(int x) {
  return lower_bound((cx).begin(), (cx).end(), x) - cx.begin() + 1;
}
int yidx(int y) {
  return lower_bound((cy).begin(), (cy).end(), y) - cy.begin() + 1;
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 1, x, y, z; i <= N; i++) {
    scanf("%d %d %d", &x, &y, &z);
    A[i] = pri(pr(x, y), z);
    cx.push_back(x), cx.push_back(y);
    cy.push_back(z);
  }
  for (int i = 1, x, y, z; i <= M; i++) {
    scanf("%d %d %d", &x, &y, &z);
    B[i] = pir(x, pr(y, z));
    cx.push_back(x);
    cy.push_back(y), cy.push_back(z);
  }
  cx.push_back(0), cy.push_back(0);
  sort((cx).begin(), (cx).end()), sort((cy).begin(), (cy).end());
  cx.resize(unique((cx).begin(), (cx).end()) - cx.begin());
  cy.resize(unique((cy).begin(), (cy).end()) - cy.begin());
  R = ((int)(cx).size()), C = ((int)(cy).size());
  v.resize(R + 2), chk1.resize(R + 2), chk2.resize(R + 2);
  for (int i = 0; i < R + 2; i++)
    v[i].resize(C + 2), chk1[i].resize(C + 2), chk2[i].resize(C + 2);
  for (int i = 1; i <= N; i++) {
    A[i].first.first = xidx(A[i].first.first);
    A[i].first.second = xidx(A[i].first.second);
    A[i].second = yidx(A[i].second);
    for (int j = A[i].first.first; j <= A[i].first.second; j++)
      chk1[j][A[i].second] = 1;
  }
  for (int i = 1; i <= M; i++) {
    B[i].first = xidx(B[i].first);
    B[i].second.first = yidx(B[i].second.first);
    B[i].second.second = yidx(B[i].second.second);
    for (int j = B[i].second.first; j <= B[i].second.second; j++)
      chk2[B[i].first][j] = 1;
  }
  int sx = xidx(0), sy = yidx(0);
  v[sx][sy] = 1, q.push(pr(sx, sy));
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    if (x == 1 || x == R + 1 || y == 1 || y == C + 1) return puts("INF"), 0;
    ans += 1LL * (cx[x - 1] - cx[x - 2]) * (cy[y - 1] - cy[y - 2]);
    if (!v[x - 1][y] && !(chk2[x - 1][y] && chk2[x - 1][y - 1])) {
      v[x - 1][y] = 1;
      q.push(pr(x - 1, y));
    }
    if (!v[x + 1][y] && !(chk2[x][y] && chk2[x][y - 1])) {
      v[x + 1][y] = 1;
      q.push(pr(x + 1, y));
    }
    if (!v[x][y - 1] && !(chk1[x][y - 1] && chk1[x - 1][y - 1])) {
      v[x][y - 1] = 1;
      q.push(pr(x, y - 1));
    }
    if (!v[x][y + 1] && !(chk1[x][y] && chk1[x - 1][y])) {
      v[x][y + 1] = 1;
      q.push(pr(x, y + 1));
    }
  }
  printf("%lld\n", ans);
  assert(ans >= 4);
}
