#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

constexpr int INF = (1 << 30);
constexpr ll LINF = (1LL << 60);

int N, M;
vector<int> A, B, C, D, E, F;

void input() {
	cin >> N >> M;
	A.resize(N);
	B.resize(N);
	C.resize(N);
	D.resize(M);
	E.resize(M);
	F.resize(M);
	for (int i = 0; i < N; ++i)
		cin >> A[i] >> B[i] >> C[i];
	for (int i = 0; i < M; ++i)
		cin >> D[i] >> E[i] >> F[i];
}

struct node {
	ll S;
	bool l, r, u, d;
	node() {
		S = 0;
		l = r = u = d = true;
	}
};

map<int, int> x, y;
vector<int> _x, _y;

void compress() {
	x[INF]; y[INF]; x[-INF]; y[-INF];
	x[0]; y[0];
	for (int i = 0; i < N; ++i) {
		x[A[i]]; x[B[i]]; y[C[i]];
	}
	for (int i = 0; i < M; ++i) {
		x[D[i]]; y[E[i]]; y[F[i]];
	}
	int t = 0;
	for (auto& e : x) {
		e.second = t++;
		_x.push_back(e.first);
	}
	t = 0;
	for (auto& e : y) {
		e.second = t++;
		_y.push_back(e.first);
	}
}

int H, W;
node grid[5050][5050];

void make_grid() {
	W = x.size() - 1;
	H = y.size() - 1;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			int dx = _x[j + 1] - _x[j];
			int dy = _y[i + 1] - _y[i];
			ll S = (ll)dx * dy;
			grid[i][j].S = S;
			if (i == 0) grid[i][j].u = false;
			if (i == H - 1) grid[i][j].d = false;
			if (j == 0) grid[i][j].l = false;
			if (j == W - 1) grid[i][j].r = false;
		}
	}
	for (int i = 0; i < N; ++i) {
		int y_idx = y[C[i]]; // y_idx-1 | y_idx
		for (int x_idx = x[A[i]]; x_idx < x[B[i]]; ++x_idx) {
			grid[y_idx][x_idx].u = false;
			grid[y_idx - 1][x_idx].d = false;
		}
	}
	for (int i = 0; i < M; ++i) {
		int x_idx = x[D[i]]; // x_idx-1 | x_idx
		for (int y_idx = y[E[i]]; y_idx < y[F[i]]; ++y_idx) {
			grid[y_idx][x_idx].l = false;
			grid[y_idx][x_idx - 1].r = false;
		}
	}
}

int visited[5050][5050];
ll res = 0;

void dfs(int sx, int sy) {
	if (visited[sy][sx]) return;
	visited[sy][sx] = 1;
	if (res == LINF) return;
	if (sx == 0 || sx == W - 1 || sy == 0 || sy == H - 1) {
		res = LINF;
		return;
	}
	res += grid[sy][sx].S;
	if (grid[sy][sx].l && !visited[sy][sx - 1])
		dfs(sx- 1, sy);
	if (grid[sy][sx].r && !visited[sy][sx + 1])
		dfs(sx + 1, sy);
	if (grid[sy][sx].u && !visited[sy - 1][sx])
		dfs(sx, sy - 1);
	if (grid[sy][sx].d && !visited[sy + 1][sx])
		dfs(sx, sy + 1);
}

void solve() {
	int x_idx = x[0];
	int y_idx = y[0];
	dfs(x_idx, y_idx);
}

int main() {
	input();
	compress();
	make_grid();
	solve();
	if (res != LINF) cout << res << endl;
	else cout << "INF" << endl;
	return 0;
}
