#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> PLL;

#define x first
#define y second

const ll N = 1e3 + 10;
const ll M = 6e3 + 10;
const ll dx[] = { 1, 0, -1, 0 };
const ll dy[] = { 0, -1, 0, 1 };

ll u[N], d[N], x[N], l[N], r[N], y[N];
bool wall[M][M], st[M][M];
ll n, m, h, w;

vector<ll> cmpX, cmpY;

void cmp(vector<ll> &v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

ll get(vector<ll> &v, ll x) {
	return lower_bound(v.begin(), v.end(), x) - v.begin();
}

void dfs(ll x, ll y) {
	st[x][y] = true;
	queue<PLL> q;
	q.push(make_pair(x, y));

	while (q.size()) {
		x = q.front().x, y = q.front().y; q.pop();
		for (ll i = 0; i < 4; i++) {
			ll nx = x + dx[i], ny = y + dy[i];
			if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if (st[nx][ny] || wall[nx][ny]) continue;
			st[nx][ny] = true;
			q.push(make_pair(nx, ny));
		}
	}
}

int main() {
	cin >> n >> m;
	for (ll i = 1; i <= n; i++) cin >> u[i] >> d[i] >> x[i];
	for (ll i = 1; i <= m; i++) cin >> y[i] >> l[i] >> r[i];

	cmpX.push_back(-2e9), cmpX.push_back(2e9);
	cmpY.push_back(-2e9), cmpY.push_back(2e9);

	for (ll i = 1; i <= n; i++) cmpX.push_back(x[i]), cmpY.push_back(u[i]), cmpY.push_back(d[i]);
	for (ll i = 1; i <= m; i++) cmpY.push_back(y[i]), cmpX.push_back(l[i]), cmpX.push_back(r[i]);
	cmp(cmpX), cmp(cmpY);
	w = cmpX.size() * 2, h = cmpY.size()*2;

	for (ll i = 1; i <= n; i++){
		ll U = get(cmpY, u[i]) * 2, D = get(cmpY, d[i]) * 2, X = get(cmpX, x[i])*2;
		for (ll j = U; j <= D; j++) wall[X][j] = true;
	}

	for(ll i = 1; i <= m; i++){
		ll L = get(cmpX, l[i]) * 2, R = get(cmpX, r[i])*2, Y = get(cmpY, y[i])*2;
		for (int j = L; j <= R; j++) wall[j][Y] = true;
	}

	ll sx = get(cmpX, 0) * 2 - 1, sy = get(cmpY, 0) * 2 - 1;

	dfs(sx, sy);

	ll res = 0;
	for (ll x = 0; x < w; x++) {
		for (ll y = 0; y < h; y++) {
			if (!st[x][y]) continue;
			if (x == 0 || x >= w - 2 || y == 0 || y >= h - 2) {
				cout << "INF" << endl;
				return 0;
			}
			if (x % 2 == 0 || y % 2 == 0) continue;
			ll X = x / 2, Y = y / 2;
			if (X + 1 >= cmpX.size() || Y + 1 >= cmpY.size()) {
				cout << "INF" << endl;
				return 0;
			}
			res += (cmpX[X + 1] - cmpX[X]) * (cmpY[Y + 1] - cmpY[Y]);
		}
	}

	cout << res << endl;

	return 0;
 }