/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - . (Single Dot)
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = 1000;
const int MAX_XN = MAX_N * 2 + MAX_M + 1;
const int MAX_YN = MAX_M * 2 + MAX_N + 1;
const int dxs[] = { 0, 1, 0, -1 }, dys[] = { 1, 0, -1, 0 };

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef queue<pii> qpii;

/* global variables */

int as[MAX_N], bs[MAX_N], cs[MAX_N];
int ds[MAX_M], es[MAX_M], fs[MAX_M];
int xs[MAX_XN], ys[MAX_YN];
bool ls[MAX_XN][MAX_YN][4], used[MAX_XN][MAX_YN];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  int xn = 0, yn = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", as + i, bs + i, cs + i);
    xs[xn++] = as[i], xs[xn++] = bs[i], ys[yn++] = cs[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", ds + i, es + i, fs + i);
    xs[xn++] = ds[i], ys[yn++] = es[i], ys[yn++] = fs[i];
  }
  xs[xn++] = ys[yn++] = 0;

  sort(xs, xs + xn);
  sort(ys, ys + yn);
  xn = unique(xs, xs + xn) - xs;
  yn = unique(ys, ys + yn) - ys;
  //printf("xn=%d, yn=%d\n", xn, yn);

  for (int i = 0; i < n; i++) {
    int x0 = lower_bound(xs, xs + xn, as[i]) - xs;
    int x1 = lower_bound(xs, xs + xn, bs[i]) - xs;
    int y = lower_bound(ys, ys + yn, cs[i]) - ys;
    for (int x = x0; x < x1; x++) {
      ls[x][y][2] = true;
      if (y > 0) ls[x][y - 1][0] = true;
    }
  }

  for (int i = 0; i < m; i++) {
    int x = lower_bound(xs, xs + xn, ds[i]) - xs;
    int y0 = lower_bound(ys, ys + yn, es[i]) - ys;
    int y1 = lower_bound(ys, ys + yn, fs[i]) - ys;
    for (int y = y0; y < y1; y++) {
      ls[x][y][3] = true;
      if (x > 0) ls[x - 1][y][1] = true;
    }
  }

  int sx = lower_bound(xs, xs + xn, 0) - xs;
  int sy = lower_bound(ys, ys + yn, 0) - ys;
  used[sx][sy] = true;
  ll s = (ll)(xs[sx + 1] - xs[sx]) * (ys[sy + 1] - ys[sy]);

  qpii q;
  q.push(pii(sx, sy));

  while (! q.empty()) {
    pii u = q.front(); q.pop();
    int ux = u.first, uy = u.second;

    for (int di = 0; di < 4; di++)
      if (! ls[ux][uy][di]) {
	int vx = ux + dxs[di], vy = uy + dys[di];
	if (vx < 0 || vx >= xn - 1 || vy < 0 || vy >= yn - 1) {
	  puts("INF");
	  return 0;
	}

	if (! used[vx][vy]) {
	  used[vx][vy] = true;
	  s += (ll)(xs[vx + 1] - xs[vx]) * (ys[vy + 1] - ys[vy]);
	  q.push(pii(vx, vy));
	}
      }
  }

  printf("%lld\n", s);
  return 0;
}
