#include "bits/stdc++.h"

using namespace std;

int main() {
	int N, M;
	cin >> N >> M ;

	vector<int>A(N), B(N), C(N);
	vector<int>D(M), E(M), F(M);

	std::set<int>x_org = {0};
	std::set<int>y_org = {0};

	struct pair3 {
		int a, b, c;
		pair3(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
	};
	std::vector<pair3>Xpair;//N ko
	std::vector<pair3>Ypair;//M ko


	for (int n = 0; n < N ; ++n) {
		cin >> A[n]>> B[n]>>C[n];
		Xpair.emplace_back(A[n], B[n], C[n]);
		x_org.insert(A[n]); 
		x_org.insert(B[n]); 
		y_org.insert(C[n]);
	}

	for (int m = 0; m < M ; ++m) {
		cin >> D[m] >> E[m] >> F[m]; 
		Ypair.emplace_back(D[m], E[m], F[m]);
		x_org.insert(D[m]);
		y_org.insert(E[m]);
		y_org.insert(F[m]); 
	}

	vector<int>X, Y;//縮小から元
	std::map<int, int>mx;//元から縮小
	std::map<int, int>my;//元から縮小
	for (auto itr = x_org.begin(); itr != x_org.end(); ++itr) {
		mx[*itr] = X.size();
		X.push_back(*itr);
	}

	for (auto itr = y_org.begin(); itr != y_org.end(); ++itr) {
		my[*itr] = Y.size();
		Y.push_back(*itr);
	}
	int x = 2 * X.size() + 1;
	int y = 2 * Y.size() + 1;

	vector<vector<int>>XY(x,vector<int>(y));//all 0
	
	for (int n = 0 ;n < (int)Xpair.size() ; ++n) {
		for (int m = mx[Xpair[n].a] * 2 + 1; m <= mx[Xpair[n].b] * 2 + 1;++m) {
			XY[m][my[Xpair[n].c]*2+1] = -1;
		}
	}

	for (int n = 0; n < (int)Ypair.size(); ++n) {
		for (int m = my[Ypair[n].b] * 2 + 1; m <= my[Ypair[n].c] * 2 + 1; ++m) {
			XY[mx[Ypair[n].a] * 2 + 1][m] = -1;
		}
	}


	queue<pair<int,int>> q; 
	XY[mx[0] * 2 + 1][my[0] * 2 + 1] = 1;
	q.emplace(mx[0] * 2 + 1, my[0] * 2 + 1);
	while (!q.empty()) {
		int x0 = q.front().first; 
		int y0 = q.front().second;
		q.pop();
		//範囲内かつ0を4セット
		{
			int x1 = x0 + 1;
			int y1 = y0;
			if ((0 <= x1) && (x > x1) && (0 <= y1)&&(y > y1)&&(0 == XY[x1][y1])) {
				XY[x1][y1] = 1;
				q.emplace(x1,y1);
			}
		}
		{
			int x1 = x0 - 1;
			int y1 = y0;
			if ((0 <= x1) && (x > x1) && (0 <= y1) && (y > y1) && (0 == XY[x1][y1])) {
				XY[x1][y1] = 1;
				q.emplace(x1, y1);
			}
		} 
		{
			int x1 = x0;
			int y1 = y0 +1;
			if ((0 <= x1) && (x > x1) && (0 <= y1) && (y > y1) && (0 == XY[x1][y1])) {
				XY[x1][y1] = 1;
				q.emplace(x1, y1);
			}
		} 
		{
			int x1 = x0;
			int y1 = y0 - 1;
			if ((0 <= x1) && (x > x1) && (0 <= y1) && (y > y1) && (0 == XY[x1][y1])) {
				XY[x1][y1] = 1;
				q.emplace(x1, y1);
			}
		}
	}

	long long nAns = 0;
	for (int a = 0;a <= (int)X.size();++a ) {//どっちかが奇数out
		for (int b = 0; b <= (int)Y.size(); ++b) {
			if (1 != XY[2*a][2*b]) {
				continue;
			}
			if ((a == 0) || (a == (int)X.size()) || (b == 0) || (b == (int)Y.size())) {
				cout << "INF" << endl;
				return 0;
			}
			long a1 = (X[a] - X[a - 1]);
			long a2 = (Y[b] - Y[b - 1]);
			nAns += a1 * a2;
		}
	}
	cout << nAns << endl;
	return 0;
}