#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }


int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	vector<ll> xd, yd;

	xd.push_back(0), yd.push_back(0);

	int n, m; cin >> n >> m;

	vector<ll> a(n), b(n), c(n), d(m), e(m), f(m);

	const ll mx = 1000000000ll;
	xd.push_back(-(mx + 5)), xd.push_back(mx + 5);
	yd.push_back(-(mx + 5)), yd.push_back(mx + 5);

	rep(i, 0, n) {
		read(a[i], b[i], c[i]);
		xd.push_back(a[i]), xd.push_back(b[i]), yd.push_back(c[i]);
	}

	rep(i, 0, m) {
		read(d[i], e[i], f[i]);
		xd.push_back(d[i]), yd.push_back(e[i]), yd.push_back(f[i]);
	}
	
	sort(all(xd)), sort(all(yd));
	{
		auto ix = unique(all(xd)); xd.erase(ix, xd.end());
		auto iy = unique(all(yd)); yd.erase(iy, yd.end());
	}

	int X = sz(xd), Y = sz(yd);

	int stx = lower_bound(all(xd), 0) - xd.begin(), sty = lower_bound(all(yd), 0) - yd.begin();

	typedef vector<vector<bool>> vvb;
	typedef vector<bool> vb;

	vvb vis(X, vb(Y, 0));
	vvb canup(X, vb(Y, 1));
	vvb candown(X, vb(Y, 1));
	vvb canleft(X, vb(Y, 1));
	vvb canright(X, vb(Y, 1));

	// process lines
	rep(i, 0, n) {
		ll aa, bb, cc;
		aa = lower_bound(all(xd), a[i]) - xd.begin();
		bb = lower_bound(all(xd), b[i]) - xd.begin();
		cc = lower_bound(all(yd), c[i]) - yd.begin();

		//write("Horz", aa, bb, cc);

		rep(j, aa, bb) canup[j][cc] = candown[j][cc - 1] = 0;
	}

	rep(i, 0, m) {
		ll dd, ee, ff;
		dd = lower_bound(all(xd), d[i]) - xd.begin();
		ee = lower_bound(all(yd), e[i]) - yd.begin();
		ff = lower_bound(all(yd), f[i]) - yd.begin();

		//write("Vert", dd, ee, ff);

		rep(j, ee, ff) canleft[dd][j] = canright[dd - 1][j] = 0;
	}

	queue<pair<int, int>> q;
	q.push({stx, sty});

	while (!q.empty()) {
		int x, y;
		tie(x, y) = q.front(); q.pop();

		if (vis[x][y]) continue;
		vis[x][y] = 1;

		if (x - 1 >= 0 && canleft[x][y]) q.push({x - 1, y});
		if (x + 1 < X && canright[x][y]) q.push({x + 1, y});
		if (y - 1 >= 0 && canup[x][y]) q.push({x, y - 1});
		if (y + 1 < Y && candown[x][y]) q.push({x, y + 1});
	}

	/*
	auto dfs = [&](auto&& f, int x, int y) -> void {
		if (vis[x][y]) return;
		vis[x][y] = 1;

		if (x - 1 >= 0 && canleft[x][y]) f(f, x - 1, y);
		if (x + 1 < X && canright[x][y]) f(f, x + 1, y);
		if (y - 1 >= 0 && canup[x][y]) f(f, x, y - 1);
		if (y + 1 < Y && candown[x][y]) f(f, x, y + 1);
	};
	*/

	bool inf = false;
	rep(j, 0, Y) if (vis[0][j] || vis[X - 1][j]) inf = true;
	rep(i, 0, X) if (vis[i][0] || vis[i][Y - 1]) inf = true;

	if (inf) {
		die("INF");
	}

	ll area = 0;
	rep(j, 1, Y - 1) {
		rep(i, 1, X - 1) {
			if (vis[i][j]) {
				area += 1ll * (xd[i + 1] - xd[i]) * (yd[j + 1] - yd[j]);
			}
		}
	}

	die(area);
}


Measured memory_bytes: 9988