#define _USE_MATH_DEFINES
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
//#include <bits/stdc++.h>

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <fstream>
#include <array>
#include <string>
#include <cstring>
#include <functional>
#include <ctime>
#include <iostream>
#include <unordered_set>
#include <complex>

#include <nmmintrin.h>
#include <mmintrin.h>
#include <emmintrin.h>


using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
//#define printe(...) void();
#define printE(...) fprintf(stderr, __VA_ARGS__);
//#define printE(...) void();


#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,P) scanf("%d %d %d %d",&n,&m,&o,&P)
#define SINT5(n,m,o,P,q) scanf("%d %d %d %d %d",&n,&m,&o,&P,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 1'010'000'000; // 0x3C33'6080
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863


template <class A, class B> inline ostream& operator<<(ostream & st, const pair<A, B> & P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B> & P, const pair<A, B> & Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B> & P, const pair<A, B> & Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };


inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



int ai[1003];
int bi[1003];
int ci[1003];
int di[1003];
int ei[1003];
int fi[1003];

bool used[4096][4096];

bool dis[4096][4096][4];

int main() {
	int n, m;

	cin >> n >> m;

	map<int, int> xzip;
	map<int, int> yzip;

	xzip[0] = 0;
	yzip[0] = 0;
	xzip[INF] = 0;
	yzip[INF] = 0;
	xzip[-INF] = 0;
	yzip[-INF] = 0;
	xzip[INF+1] = 0;
	yzip[INF+1] = 0;
	xzip[-INF-1] = 0;
	yzip[-INF-1] = 0;

	rep(i, n) {
		cin >> ai[i] >> bi[i] >> ci[i];
		xzip[ai[i]] = 0;
		xzip[bi[i]] = 0;
		yzip[ci[i]] = 0;
	}
	rep(i, m) {
		cin >> di[i] >> ei[i] >> fi[i];
		xzip[di[i]] = 0;
		yzip[ei[i]] = 0;
		yzip[fi[i]] = 0;
	}
	vector<int> xunzip;
	vector<int> yunzip;
	int xc = -1;
	for (auto& p : xzip) {
		p.second = ++xc;
		xunzip.push_back(p.first);
	}
	int yc = -1;
	for (auto& p : yzip) {
		p.second = ++yc;
		yunzip.push_back(p.first);
	}
	++xc; ++yc;

	assert(xc < 4000);
	assert(yc < 4000);

	const int dx[4] = { 1,-1,0,0 };
	const int dy[4] = { 0,0,1,-1 };
	const int RR = 0;
	const int LL = 1;
	const int DD = 2;
	const int UU = 3;

	using PP = pair<Pi, Pi>;
	//set<PP> dis;
	rep(i, n) {
		int a = xzip[ai[i]];
		int b = xzip[bi[i]];
		int c = yzip[ci[i]];
		for (int y = a; y < b; ++y) {
			dis[c - 1][y][LL] = true;
			dis[c][y][RR] = true;;
		}
	}
	rep(i, m) {
		int d = xzip[di[i]];
		int e = yzip[ei[i]];
		int f = yzip[fi[i]];
		for (int x = e; x < f; ++x) {
			dis[x][d - 1][UU] = true;
			dis[x][d][DD] = true;
		}
	}

	queue<Pi> q;
	used[xzip[0]][yzip[0]] = true;
	q.push({ xzip[0], yzip[0] });
	while (!q.empty()) {
		auto p = q.front(); q.pop();
		rep(d, 4) {
			int x = p.first  + dx[d];
			int y = p.second + dy[d];
			if (y < 0 || y >= yc-1) continue;
			if (x < 0 || x >= xc-1) continue;
			if (used[x][y]) continue;
			//if (dis.count({ p, {x,y} })) continue;
			if (dis[x][y][d]) continue;
			used[x][y] = true;
			q.push({y, x});
		}
	}
	ll ret = 0;
	bool isinf = false;

	rep(i, yc-1) {
		rep(j, xc-1) {
			ll v = !used[j][i] ? 0LL : ll(xunzip[j + 1] - xunzip[j]) * ll(yunzip[i + 1] - yunzip[i]);
			printe((v > 0 ? v > 99 ? " #" : "%2lld" : " ."), v);
			ret += v;
			if (v > 0 && (i == 0 || j == 0 || i == yc - 2 || j == xc - 2)) {
				isinf = true;
			}
		}
		printe("\n");
	}
	if (isinf) {
		cout << "INF" << endl;
	} else {
		assert(ret > 0);
		assert(ret >= 4);
		if (ret < 4) {
			for (;;) puts("aaaaaaaaaaaaaaaaaaaaaa");
		}
		cout << ret << endl;
	}


}


