#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

const int MAX_POS = 1000 * 1000 * 1000 + 1;

struct cell {
	cell() : area(0), l(true), r(true), u(true), d(true)
	{}

	int code() const {
		int c = 0;
		if (d) c |= 1;
		if (r) c |= 2;
		if (u) c |= 4;
		if (l) c |= 8;
		return c;
	}

	long long area;
	bool l, r, u, d;
};

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(N), B(N), C(N);
	vector<int> D(M), E(M), F(M);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i] >> C[i];
	}
	for (int j = 0; j < M; ++j) {
		cin >> D[j] >> E[j] >> F[j];
	}

	vector<long long> p;
	p.push_back(0);
	p.push_back(MAX_POS);
	p.push_back(-MAX_POS);
	for (int i = 0; i < N; ++i) {
		p.push_back(A[i]);
		p.push_back(B[i]);
		p.push_back(C[i]);
	}
	for (int j = 0; j < M; ++j) {
		p.push_back(D[j]);
		p.push_back(E[j]);
		p.push_back(F[j]);
	}
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());

	const int L = p.size() - 1;

	vector<vector<cell>> f(L, vector<cell>(L));

	for (int i = 0; i < L; ++i) {
		for (int j = 0; j < L; ++j) {
			f[i][j].area = (p[i + 1] - p[i]) * (p[j + 1] - p[j]);
		}
	}

	for (int i = 0; i < N; ++i) {
		auto j = lower_bound(p.begin(), p.end(), C[i]) - p.begin();
		for (int k = 0; k < L; ++k) {
			if (A[i] <= p[k] && p[k + 1] <= B[i]) {
				f[k][j - 1].r = f[k][j].l = false;
			}
		}
	}
	for (int j = 0; j < M; ++j) {
		auto i = lower_bound(p.begin(), p.end(), D[j]) - p.begin();
		for (int k = 0; k + 1 < L; ++k) {
			if (E[j] <= p[k] && p[k + 1] <= F[j]) {
				f[i - 1][k].d = f[i][k].u = false;
			}
		}
	}

	int y0 = lower_bound(p.begin(), p.end(), 0) - p.begin();
	int x0 = y0;

	long long ans = 0;
	vector<vector<bool>> visited(L, vector<bool>(L, false));
	queue<int> q;
	q.push(y0);
	q.push(x0);
	while (!q.empty()) {
		int y = q.front();
		q.pop();
		int x = q.front();
		q.pop();
		if (x < 1 || L <= x || y < 1 || L <= y) {
			cout << "INF" << endl;
			return 0;
		}
		if (!visited[y][x]) {
			visited[y][x] = true;
			ans += f[y][x].area;
			if (f[y][x].l) {
				q.push(y);
				q.push(x - 1);
			}
			if (f[y][x].r) {
				q.push(y);
				q.push(x + 1);
			}
			if (f[y][x].u) {
				q.push(y - 1);
				q.push(x);
			}
			if (f[y][x].d) {
				q.push(y + 1);
				q.push(x);
			}
		}
	}
	cout << ans << endl;
}
