#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
	rep(i, n) cin >> a[i] >> b[i] >> c[i];
	rep(i, m) cin >> d[i] >> e[i] >> f[i];
	
	vector<int> xs;
	xs.push_back(0);
	for(int x: a) xs.push_back(x);
	for(int x: b) xs.push_back(x);
	for(int x: d) xs.push_back(x);
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	map<int, int> xm;
	rep(i, xs.size()) xm[xs[i]] = i;

	vector<int> ys;
	ys.push_back(0);
	for(int y: c) ys.push_back(y);
	for(int y: e) ys.push_back(y);
	for(int y: f) ys.push_back(y);
	sort(ys.begin(), ys.end());
	ys.erase(unique(ys.begin(), ys.end()), ys.end());
	map<int, int> ym;
	rep(i, ys.size()) ym[ys[i]] = i;

	vector<vector<bool>> visited(xs.size() * 2, vector<bool>(ys.size() * 2, false));
	vector<ll> xd(xs.size() * 2, 0);
	rep(i, xs.size() - 1) xd[i * 2 + 1] = xs[i + 1] - xs[i];
	vector<ll> yd(ys.size() * 2, 0);
	rep(i, ys.size() - 1) yd[i * 2 + 1] = ys[i + 1] - ys[i];

	rep(i, n) {
		int y = ym[c[i]] * 2;
		for(int x = xm[a[i]] * 2; x < xm[b[i]] * 2; x++)
			visited[x][y] = true;
	}
	rep(i, m) {
		int x = xm[d[i]] * 2;
		for(int y = ym[e[i]] * 2; y < ym[f[i]] * 2; y++)
			visited[x][y] = true;
	}
	queue<P> q;
	q.emplace(xm[0] * 2, ym[0] * 2);
	int dx[] = {1, 0, -1, 0};
	int dy[] = {0, 1, 0, -1};
	ll ans = 0;
	while(!q.empty()) {
		auto p = q.front(); q.pop();
		int x = p.first, y = p.second;
		if (x < 0 || x >= xs.size() * 2 || y < 0 || y >= ys.size() * 2) {
			cout << "INF" << endl;
			return 0;
		}
		if (visited[x][y]) continue;
		visited[x][y] = true;
		ans += xd[x] * yd[y];
		rep(i, 4) q.emplace(x + dx[i], y + dy[i]);
	}
	cout << ans << endl;
}
