#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
const ld EPS = 1e-10;
template <typename T>
bool chmax(T &x, const T &y) {
  return (x < y) ? (x = y, true) : false;
};
template <typename T>
bool chmin(T &x, const T &y) {
  return (x > y) ? (x = y, true) : false;
};
int main() {
  int N, M;
  cin >> N >> M;
  int A[N], B[N], C[N];
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i];
  int D[M], E[M], F[M];
  for (int i = 0; i < M; i++) cin >> D[i] >> E[i] >> F[i];
  map<int, int> mpx, mpy;
  mpx[-inf]++, mpx[inf]++, mpy[-inf]++, mpy[inf]++;
  mpx[0]++, mpy[0]++;
  for (int i = 0; i < N; i++) {
    mpx[A[i]]++, mpx[B[i]]++, mpy[C[i]]++;
  }
  for (int i = 0; i < M; i++) {
    mpx[D[i]]++, mpy[E[i]]++, mpy[F[i]]++;
  }
  int n = 0, m = 0;
  for (auto &e : mpx) e.second = n++;
  for (auto &e : mpy) e.second = m++;
  int xs[n], ys[m];
  for (auto &e : mpx) xs[e.second] = e.first;
  for (auto &e : mpy) ys[e.second] = e.first;
  set<pii> es[n - 1][m - 1];
  for (int i = 0; i < N; i++) {
    int a = mpx[A[i]], b = mpx[B[i]], c = mpy[C[i]];
    for (int j = a; j <= b - 1; j++) {
      es[j][c - 1].insert(pii(j, c));
      es[j][c].insert(pii(j, c - 1));
    }
  }
  for (int i = 0; i < M; i++) {
    int d = mpx[D[i]], e = mpy[E[i]], f = mpy[F[i]];
    for (int j = e; j <= f - 1; j++) {
      es[d - 1][j].insert(pii(d, j));
      es[d][j].insert(pii(d - 1, j));
    }
  }
  ll dx[n - 1], dy[m - 1];
  for (int i = 0; i < n - 1; i++) dx[i] = xs[i + 1] - xs[i];
  for (int i = 0; i < m - 1; i++) dy[i] = ys[i + 1] - ys[i];
  int sx = mpx[0], sy = mpy[0];
  ll ans = 0;
  bool used[n - 1][m - 1];
  fill(used[0], used[n - 1], false);
  queue<pii> que;
  que.push(pii(sx, sy));
  while (!que.empty()) {
    int x = que.front().first, y = que.front().second;
    que.pop();
    if (used[x][y]) continue;
    if (x == 0 || x == n - 2 || y == 0 || y == m - 2) {
      cout << "INF" << endl;
      return 0;
    }
    used[x][y] = true;
    ans += dx[x] * dy[y];
    for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++) {
        if (abs(i + j) != 1) continue;
        int nx = x + i, ny = y + j;
        if (es[x][y].count(pii(nx, ny)) || used[nx][ny]) continue;
        que.push(pii(nx, ny));
      }
  }
  cout << ans << endl;
}
