#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

template<typename T, size_t N> istream & operator>>(istream & s, array<T, N> & a) { RF(e, a) { s >> e; } return s; }
template<typename T, size_t N> ostream & operator<<(ostream & s, array<T, N> const & a) {
	inc(i, SI(a)) { s << (i == 0 ? "" : " ") << a[i]; }
	return s;
}

#define UQwoS(v) v.erase(unique(ALL(v)), v.end())
#define UQ(v) sort(ALL(v)); UQwoS(v)

template<typename T> T MV(T v) { return v; }
template<typename T, typename ... U> auto MV(T v, int a, U ... b) { return vector<decltype(MV(v, b ...))>(a, MV(v, b ...)); }

#define LB(v, x) (lower_bound(ALL(v), x) - v.begin())
#define UB(v, x) (upper_bound(ALL(v), x) - v.begin())

int main() {
	IN(int, n, m);
	vector<array<LL, 3>> tate(n), yoko(m);
	cin >> tate >> yoko;
	
	LL L_INF =             1'000'000'000 + 1;
	LL S_INF = 4'000'000'000'000'000'000 + 1;
	vector<LL> I = { -L_INF, 0, +L_INF }, J = I;
	for(auto [a, b, c]: tate) {
		I.PB(a);
		I.PB(b);
		J.PB(c);
	}
	for(auto [d, e, f]: yoko) {
		I.PB(d);
		J.PB(e);
		J.PB(f);
	}
	UQ(I);
	UQ(J);
	
	int h = 2 * SI(I) - 1;
	int w = 2 * SI(J) - 1;
	auto v = MV<LL>(0, h, w);
	inc(i, h) {
	inc(j, w) {
		if(i % 2 == 0 && j % 2 == 0) { v[i][j] = -1; }
		ef(i % 2 != 0 && j % 2 != 0) {
			if(i == 1 || i == h - 2 || j == 1 || j == w - 2) { v[i][j] = S_INF; }
			else { v[i][j] = (I[i/2 + 1] - I[i/2]) * (J[j/2 + 1] - J[j/2]); }
		}
	}
	}
	
	for(auto [a, b, c]: tate) {
		int aa = LB(I, a) * 2;
		int bb = LB(I, b) * 2;
		int cc = LB(J, c) * 2;
		incII(ii, aa, bb) { v[ii][cc] = -1; }
	}
	for(auto [d, e, f]: yoko) {
		int dd = LB(I, d) * 2;
		int ee = LB(J, e) * 2;
		int ff = LB(J, f) * 2;
		incII(jj, ee, ff) { v[dd][jj] = -1; }
	}
	
	int si = LB(I, 0) * 2;
	int sj = LB(J, 0) * 2;
	v[si][sj] = 0;
	
	auto vis = MV<int>(0, h, w);
	LL ans = 0;
	function<void(int, int)> dfs = [&](int i, int j) {
		if(vis[i][j]) { return; }
		vis[i][j] = 1;
		if(v[i][j] == -1) { return; }
		if(v[i][j] == S_INF) { OUT("INF"); exit(0); }
		ans += v[i][j];
		inc(k, 4) {
			vector<int> di = { +1,  0, -1,  0, +1, +1, -1, -1, 0 };
			vector<int> dj = {  0, +1,  0, -1, +1, -1, +1, -1, 0 };
			int ii = i + di[k];
			int jj = j + dj[k];
			if_not(inID(ii, 0, h) && inID(jj, 0, w)) { continue; }
			
			dfs(ii, jj);
		}
	};
	dfs(si, sj);
	//assert(ans < S_INF);
	OUT(ans);
}
