#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)

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

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 ...)); }

int main() {
	IN(int, n, m);
	vector<array<LL, 3>> tate(n), yoko(m);
	cin >> tate >> yoko;
	
	LL INF = 1'000'000'000 + 1;
	tate.PB({ -INF, +INF, -INF });
	tate.PB({ -INF, +INF, +INF });
	yoko.PB({ -INF, -INF, +INF });
	yoko.PB({ +INF, -INF, +INF });
	vector<LL> I, J;
	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);
	}
	I.PB(0);
	J.PB(0);
	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, SI(I) - 1) {
	inc(j, SI(J) - 1) {
		v[2 * i + 1][2 * j + 1] = (I[i + 1] - I[i]) * (J[j + 1] - J[j]);
	}
	}
	for(auto [a, b, c]: tate) {
		int aa = 2 * LB(I, a);
		int bb = 2 * LB(I, b);
		int cc = 2 * LB(J, c);
		incII(ii, aa, bb) { v[ii][cc] = -1; }
	}
	for(auto [d, e, f]: yoko) {
		int dd = 2 * LB(I, d);
		int ee = 2 * LB(J, e);
		int ff = 2 * LB(J, f);
		incII(jj, ee, ff) { v[dd][jj] = -1; }
	}
	
	int si = 2 * LB(I, 0) - 1;
	int sj = 2 * LB(J, 0) - 1;
	stack<pair<int, int>> st;
	st.emplace(si, sj);
	LL ans = 0;
	until(st.empty()) {
		auto [i, j] = st.top(); st.pop();
		if(v[i][j] == -1) { continue; }
		if(i == 1 || i == h - 2 || j == 1 || j == w - 2) { OUT("INF"); exit(0); }
		ans += v[i][j];
		v[i][j] = -1;
		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] * 2;
			int jj = j + dj[k] * 2;
			int im = i + di[k];
			int jm = j + dj[k];
			if_not(inID(ii, 0, h) && inID(jj, 0, w)) { continue; }
			
			if(v[im][jm] == -1 || v[ii][jj] == -1) { continue; }
			st.emplace(ii, jj);
		}
	}
	OUT(ans);
}


Measured memory_bytes: 325696