#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

long long N, A[1 << 18], B[1 << 18], C[1 << 18];
long long M, D[1 << 18], E[1 << 18], F[1 << 18];
vector<long long> X, Y;

bool used[8009][8009];
bool flag[8009][8009];

int main() {
	scanf("%lld%lld", &N, &M);
	for (int i = 1; i <= N; i++) scanf("%lld%lld%lld", &A[i], &B[i], &C[i]);
	for (int i = 1; i <= M; i++) scanf("%lld%lld%lld", &D[i], &E[i], &F[i]);

	// 座圧
	for (int i = 1; i <= N; i++) {
		X.push_back(A[i]);
		X.push_back(B[i]);
		Y.push_back(C[i]);
	}
	for (int i = 1; i <= M; i++) {
		X.push_back(D[i]);
		Y.push_back(E[i]);
		Y.push_back(F[i]);
	}
	X.push_back(0);
	Y.push_back(0);
	sort(X.begin(), X.end()); X.erase(unique(X.begin(), X.end()), X.end());
	sort(Y.begin(), Y.end()); Y.erase(unique(Y.begin(), Y.end()), Y.end());

	for (int i = 1; i <= N; i++) {
		int pos1 = lower_bound(X.begin(), X.end(), A[i]) - X.begin();
		int pos2 = lower_bound(X.begin(), X.end(), B[i]) - X.begin();
		int pos3 = lower_bound(Y.begin(), Y.end(), C[i]) - Y.begin();
		for (int j = (pos1 + 1) * 2; j <= (pos2 + 1) * 2; j++) used[j][(pos3 + 1) * 2] = true;
	}
	for (int i = 1; i <= M; i++) {
		int pos1 = lower_bound(X.begin(), X.end(), D[i]) - X.begin();
		int pos2 = lower_bound(Y.begin(), Y.end(), E[i]) - Y.begin();
		int pos3 = lower_bound(Y.begin(), Y.end(), F[i]) - Y.begin();
		for (int j = (pos2 + 1) * 2; j <= (pos3 + 1) * 2; j++) used[(pos1 + 1) * 2][j] = true;
	}

	queue<pair<int, int>> Q;
	int pos1 = lower_bound(X.begin(), X.end(), 0) - X.begin();
	int pos2 = lower_bound(Y.begin(), Y.end(), 0) - Y.begin();
	flag[(pos1 + 1) * 2][(pos2 + 1) * 2] = true; Q.push(make_pair((pos1 + 1) * 2, (pos2 + 1) * 2));

	/*for (int i = 1; i <= 2 * X.size() + 1; i++) {
		for (int j = 1; j <= 2 * Y.size() + 1; j++) {
			if (used[i][j] == true) cout << "#";
			else if (flag[i][j] == true) cout << ".";
			else cout << " ";
		}
		cout << endl;
	}*/

	while (!Q.empty()) {
		int sx = Q.front().first, sy = Q.front().second; Q.pop();
		int dx[4] = { -1, 0, 1, 0 };
		int dy[4] = { 0, 1, 0, -1 };
		for (int i = 0; i < 4; i++) {
			int tx = sx + dx[i], ty = sy + dy[i];
			if (tx < 1 || ty < 1 || tx >= 2 * X.size() + 2 || ty >= 2 * Y.size() + 2 || flag[tx][ty] == true || used[tx][ty] == true) continue;
			flag[tx][ty] = true;
			Q.push(make_pair(tx, ty));
		}
	}

	long long sum = 0;
	for (int i = 1; i <= 2 * X.size() + 1; i += 2) {
		for (int j = 1; j <= 2 * Y.size() + 1; j += 2) {
			if (flag[i][j] == false) continue;
			if (i == 1 || j == 1 || i == 2 * X.size() + 1 || j == 2 * Y.size() + 1) {
				cout << "INF" << endl;
				return 0;
			}
			long long vx = (i - 2) / 2;
			long long vy = (j - 2) / 2;
			sum += (X[vx + 1] - X[vx]) * (Y[vy + 1] - Y[vy]);
		}
	}
	cout << sum << endl;
	return 0;
}