/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more scores.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

int a[1010];
int b[1010];
int c[1010];
int d[1010];
int e[1010];
int f[1010];
int x[3030];
int y[3030];
int L[3030][3030];
int R[3030][3030];
int U[3030][3030];
int D[3030][3030];
int vis[3030][3030];

ll res;
int mix;
int mxx;
int miy;
int mxy;
int N, M;

inline int px(int v) { return lower_bound(x + 1, x + 1 + N, v) - x; }
inline int py(int v) { return lower_bound(y + 1, y + 1 + M, v) - y; }

inline void BFS(int p, int q) {
	queue<int>P, Q;
	P.push(p), Q.push(q);
	vis[p][q] = 1;
	while(!P.empty()) {
		p = P.front(), q = Q.front(), P.pop(), Q.pop();
		chkmin(mix, p), chkmax(mxx, p);
		chkmin(miy, q), chkmax(mxy, q);
		res += 1LL * (x[p + 1] - x[p]) * (y[q + 1] - y[q]);
		int tp, tq;
		tp = p - 1, tq = q;
		if(!L[p][q] && !vis[tp][tq] && tp >= 1) {
			vis[tp][tq] = 1;
			P.push(tp), Q.push(tq);
		}
		tp = p + 1, tq = q;
		if(!R[p][q] && !vis[tp][tq] && tp <= N) {
			vis[tp][tq] = 1;
			P.push(tp), Q.push(tq);
		}
		tp = p, tq = q - 1;
		if(!U[p][q] && !vis[tp][tq] && tq >= 1) {
			vis[tp][tq] = 1;
			P.push(tp), Q.push(tq);
		}
		tp = p, tq = q + 1;
		if(!D[p][q] && !vis[tp][tq] && tq <= M) {
			vis[tp][tq] = 1;
			P.push(tp), Q.push(tq);
		}
	}
}

int main() {
#ifdef LOCAL
	FILE("a");
#endif

	int n = ri, m = ri;
	x[++N] = 0, x[++N] = -1000000001, x[++N] = 1000000001;
	y[++M] = 0, y[++M] = -1000000001, y[++M] = 1000000001;
	for(int i = 1; i <= n; i++) {
		x[++N] = a[i] = ri;
		x[++N] = b[i] = ri;
		y[++M] = c[i] = ri;
	}
	for(int i = 1; i <= m; i++) {
		x[++N] = d[i] = ri;
		y[++M] = e[i] = ri;
		y[++M] = f[i] = ri;
	}

	sort(x + 1, x + 1 + N);
	sort(y + 1, y + 1 + M);

	N = unique(x + 1, x + 1 + N) - x - 1;
	M = unique(y + 1, y + 1 + M) - y - 1;

	mix = N + 1, mxx = 0;
	miy = M + 1, mxy = 0;

	for(int i = 1; i <= n; i++) {
		a[i] = lower_bound(x + 1, x + 1 + N, a[i]) - x;
		b[i] = lower_bound(x + 1, x + 1 + N, b[i]) - x;
		c[i] = lower_bound(y + 1, y + 1 + M, c[i]) - y;
		for(int j = a[i]; j < b[i]; j++)
			U[j][c[i]] = D[j][c[i] - 1] = 1;
	}
	for(int i = 1; i <= m; i++) {
		d[i] = lower_bound(x + 1, x + 1 + N, d[i]) - x;
		e[i] = lower_bound(y + 1, y + 1 + M, e[i]) - y;
		f[i] = lower_bound(y + 1, y + 1 + M, f[i]) - y;
		for(int j = e[i]; j < f[i]; j++)
			L[d[i]][j] = R[d[i] - 1][j] = 1;
	}

	int x = px(0), y = py(0);

	BFS(x, y);

	if(mix == 1 || mxx == N || miy == 1 || mxy == M) puts("INF");
	else printf("%lld\n", res);
	
	return 0;
}

Measured memory_bytes: 114752