#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 1005 * 3, inf = 1e9 + 7;
const int dx[] = { -1, 1, 0, 0 }, dy[] = { 0, 0, -1, 1 };

int n, m;
int ro[mxn][mxn], co[mxn][mxn];
int a[mxn], b[mxn], c[mxn], d[mxn], e[mxn], f[mxn];
int vx[mxn], xsz, vy[mxn], ysz;
bool ban[mxn][mxn][4], vis[mxn][mxn];
int que[mxn * mxn * 2], ql, qr;

int main() {
	scanf("%d %d", &n, &m);
	vx[xsz ++] = -inf, vx[xsz ++] = inf, vx[xsz ++] = 0;
	vy[ysz ++] = -inf, vy[ysz ++] = inf, vy[ysz ++] = 0;
	rep(i, n) scanf("%d %d %d", &a[i], &b[i], &c[i]), vx[xsz ++] = a[i], vx[xsz ++] = b[i], vy[ysz ++] = c[i];
	rep(i, m) scanf("%d %d %d", &d[i], &e[i], &f[i]), vx[xsz ++] = d[i], vy[ysz ++] = e[i], vy[ysz ++] = f[i];
	sort(vx, vx + xsz); xsz = unique(vx, vx + xsz) - vx; sort(vy, vy + ysz), ysz = unique(vy, vy + ysz) - vy;
	rep(i, n) {
		a[i] = lower_bound(vx, vx + xsz, a[i]) - vx;
		b[i] = lower_bound(vx, vx + xsz, b[i]) - vx;
		c[i] = lower_bound(vy, vy + ysz, c[i]) - vy;
		co[a[i]][c[i]] ++, co[b[i]][c[i]] --;
	}
	rep(i, m) {
		d[i] = lower_bound(vx, vx + xsz, d[i]) - vx;
		e[i] = lower_bound(vy, vy + ysz, e[i]) - vy;
		f[i] = lower_bound(vy, vy + ysz, f[i]) - vy;
		ro[d[i]][e[i]] ++, ro[d[i]][f[i]] --;
	}
	rep(i, xsz) rep(j, ysz) {
		if (i) co[i][j] += co[i - 1][j];
		if (j) ro[i][j] += ro[i][j - 1];
	}
	rep(i, xsz) rep(j, ysz) {
		ban[i][j][0] = ro[i][j] > 0;
		ban[i][j][1] = ro[i + 1][j] > 0;
		ban[i][j][2] = co[i][j] > 0;
		ban[i][j][3] = co[i][j + 1] > 0;
	}
	int sx = lower_bound(vx, vx + xsz, 0) - vx;
	int sy = lower_bound(vy, vy + ysz, 0) - vy;
	ll ans = 0;
	vis[sx][sy] = 1, que[qr ++] = sx, que[qr ++] = sy;
	while (ql < qr) {
		int x = que[ql ++], y = que[ql ++];
		if (x == 0 || x + 1 == xsz - 1 || y == 0 || y + 1 == ysz - 1) { puts("INF"); return 0; }
		ans += 1LL * (vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
		rep(d, 4) if (!ban[x][y][d]) {
			int nx = x + dx[d], ny = y + dy[d];
			if (nx < 0 || ny < 0 || nx >= xsz - 1 || ny >= ysz - 1 || vis[nx][ny]) continue;
			vis[nx][ny] = 1, que[qr ++] = nx, que[qr ++] = ny;
		}
	}
	printf("%lld\n", ans);
	return 0;
}
