#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

map<ll, ll> Vx, Vy;
ll Wx[4010];
ll Wy[4010];
short mov[5][4010][4010];

int main() {
	ll N, M;
	for (int i = 0;i < 4010;i++) {
		for (int j = 0;j < 4010;j++) {
			for (int k = 0;k < 5;k++)mov[k][i][j] = 0;
		}
		Wx[i] = 0;
		Wy[i] = 0;
	}
	cin >> N >> M;
	ll A, B, C, D, E, F, mxx, mxy;
	vector<tuple<ll, ll, ll>> abc(N), def(M);
	Vx.insert({ 0,0 });
	Vy.insert({ 0,0 });
	for (int i = 0;i < N;i++) {
		cin >> A >> B >> C;
		Vx.insert({ A,0 });
		Vx.insert({ B,0 });
		Vy.insert({ C,0 });
		abc[i] = make_tuple(A, B, C);
	}
	for (int i = 0;i < M;i++) {
		cin >> C >> A >> B;
		Vy.insert({ A,0 });
		Vy.insert({ B,0 });
		Vx.insert({ C,0 });
		def[i] = make_tuple(A, B, C);
	}
	A = 1;
	B = 0;
	for (auto& au : Vx) {
		au.second = A;
		Wx[A - 1] = au.first - B;
		B = au.first;
		A++;
	}
	mxx = Vx.size();
	A = 1;
	B = 0;
	for (auto& au : Vy) {
		au.second = A;
		Wy[A - 1] = au.first - B;
		B = au.first;
		A++;
	}
	mxy = Vy.size();

	for (int i = 0;i < N;i++) {
		tie(A, B, C) = abc[i];
		D = Vx[A];
		E = Vx[B];
		F = Vy[C];
		mov[0][D][F] += 1;
		mov[0][E][F] -= 1;
		mov[1][D][F - 1] += 1;
		mov[1][E][F - 1] -= 1;
	}
	for (int i = 0;i < M;i++) {
		tie(A, B, C) = def[i];
		D = Vy[A];
		E = Vy[B];
		F = Vx[C];
		mov[2][F][D] += 1;
		mov[2][F][E] -= 1;
		mov[3][F - 1][D] += 1;
		mov[3][F - 1][E] -= 1;
	}
	for (int i = 0;i < 4010;i++) {
		for (int j = 1;j < 4010;j++) {
			mov[0][j][i] += mov[0][j - 1][i];
			mov[1][j][i] += mov[1][j - 1][i];

			mov[2][i][j] += mov[2][i][j - 1];
			mov[3][i][j] += mov[3][i][j - 1];
		}
	}

	queue<pair<ll, ll>> Q;
	Q.push({ Vx[0],Vy[0] });
	ll ans = 0;
	while (!Q.empty()) {
		tie(A, B) = Q.front();
		Q.pop();
		if (mov[4][A][B])continue;
		mov[4][A][B] = 1;

		if (A == 0 || A == mxx || B == 0 || B == mxy) {
			cout << "INF" << endl;
			return 0;
		}

		ans += Wx[A] * Wy[B];

		if (mov[0][A][B] == 0) {
			if (mov[4][A][B - 1] == 0)
				Q.push({ A,B - 1 });
		}
		if (mov[1][A][B] == 0) {
			if (mov[4][A][B + 1] == 0)
				Q.push({ A,B + 1 });
		}
		if (mov[2][A][B] == 0) {
			if (mov[4][A - 1][B] == 0)
				Q.push({ A - 1,B });
		}
		if (mov[3][A][B] == 0) {
			if (mov[4][A + 1][B] == 0)
				Q.push({ A + 1,B });
		}
	}
	cout << ans << endl;
}