#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

const ll INF = (ll)(9e+18);
const int dx[4] = { 0, 1, 0, -1 };
const int dz[4] = { -1, 0, 1, 0 };
int N, M;
vector<int> A, B, C, D, E, F;
vector<int> val_x, val_z;
map<int, int> idx_x, idx_z;
vector<int> X, Z;
vector<string> G;
int org_x, org_z;
queue<pi> Q;

void input_init(void) {
	cin >> N >> M;
	A.resize(N); B.resize(N); C.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i] >> C[i];
		val_x.push_back(C[i]);
		val_z.push_back(A[i]);
		val_z.push_back(B[i]);
	}
	D.resize(M); E.resize(M); F.resize(M);
	for (int i = 0; i < M; ++i) {
		cin >> D[i] >> E[i] >> F[i];
		val_z.push_back(D[i]);
		val_x.push_back(E[i]);
		val_x.push_back(F[i]);
	}
	sort(val_x.begin(), val_x.end());
	val_x.erase(unique(val_x.begin(), val_x.end()), val_x.end());
	sort(val_z.begin(), val_z.end());
	val_z.erase(unique(val_z.begin(), val_z.end()), val_z.end());
}

void make_axis(void) {
	for (int i = 0; i < (int)val_x.size(); ++i)
		idx_x[val_x[i]] = 2 * i;
	for (int i = 0; i < (int)val_z.size(); ++i)
		idx_z[val_z[i]] = 2 * i;
}

void make_map(void) {
	int sx = idx_x.size();
	int sz = idx_z.size();
	G.resize(sz + sz - 1, string(sx + sx - 1, ' '));
	for (int j = 0; j < sz + sz - 1; ++j) {
		for (int i = 0; i < sx + sx - 1; ++i) {
			if (j % 2 == 1 && i % 2 == 1)
				G[j][i] = '.';
		}
	}
	for (int i = 0; i < N; ++i) {
		int id = idx_x[C[i]];
		for (int j = 0; j < sz + sz - 1; ++j) {
			if (j >= idx_z[A[i]] && j <= idx_z[B[i]])
				G[j][id] = '#';
		}
	}
	for (int i = 0; i < M; ++i) {
		int id = idx_z[D[i]];
		for (int j = 0; j < sx + sx - 1; ++j) {
			if (j >= idx_x[E[i]] && j <= idx_x[F[i]])
				G[id][j] = '#';
		}
	}
}

bool set_org(void) {
	int sx = val_x.size();
	if (val_x[0] > 0 || val_x[sx - 1] < 0)
		return false;
	for (int i = 0; i < sx; ++i) {
		if (val_x[i] <= 0 && val_x[i + 1] >= 0) {
			org_x = 2 * i + 1;
			break;
		}
	}
	int sz = val_z.size();
	if (val_z[0] > 0 || val_z[sz - 1] < 0)
		return false;
	for (int i = 0; i < sz; ++i) {
		if (val_z[i] <= 0 && val_z[i + 1] >= 0) {
			org_z = 2 * i + 1;
			break;
		}
	}
	G[org_z][org_x] = '@';
	return true;
}

ll calcu_aria(int x, int z) {
	int id_x = (x - 1) / 2;
	int id_z = (z - 1) / 2;
	ll d_x = (ll)(val_x[id_x + 1] - val_x[id_x]);
	ll d_z = (ll)(val_z[id_z + 1] - val_z[id_z]);
	return d_x * d_z;
}

ll solve(void) {
	int sx = G[0].size();
	int sz = G.size();
	ll sum = (ll)0;
	Q.push(make_pair(org_x, org_z));

	while (!Q.empty()) {
		pi P = Q.front();
		int cur_x = P.first;
		int cur_z = P.second;
		Q.pop();
		if (cur_x < 0 || cur_x >= sx || cur_z < 0 || cur_z >= sz)
			return INF;
		sum += calcu_aria(cur_x, cur_z);

		for (int i = 0; i < 4; i++) {
			if (G[cur_z + dz[i]][cur_x + dx[i]] != '#') {
				int nx = cur_x + 2 * dx[i];
				int nz = cur_z + 2 * dz[i];
				if (nx < 0 || nx >= sx || nz < 0 || nz >= sz)
					return INF;
				if (G[nz][nx] == '.') {
					G[nz][nx] = '*';
					Q.push(make_pair(nx, nz));
				}
			}
		}
	}
	return sum;
}

int main(void) {
	input_init();
	make_axis();
	make_map();
	if (!set_org()) {
		cout << "INF" << '\n';
		return 0;
	}
	ll ans = solve();
	if (ans == INF)
		cout << "INF" << '\n';
	else
		cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 39100