//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=3e3+100;
const ll INF=1e18;

int w, h;
ll area[N][N];
ll ans;

int movx[4] = {0,1,0,-1};
int movy[4] = {1,0,-1,0};
bool block[N][N][4];
bool vis[N][N];

void check(int i, int j){
	if(i<0 || i>=h || j<0 || j>=w){
		cout<<"INF"<<endl;
		exit(0);
	}
}

void bfs(int i, int j){
	queue<ii> Q;
	Q.push(mp(i,j));
	check(i,j);
	vis[i][j]=1;
	while(!Q.empty()){
		i = Q.front().ff;
		j = Q.front().ss;
		Q.pop();
		ans += area[i][j];
		For(k,0,4) if(!block[i][j][k]){
			int nxti = i + movy[k];
			int nxtj = j + movx[k];
			check(nxti,nxtj);
			if(!vis[nxti][nxtj]){
				vis[nxti][nxtj]=1;
				Q.push(mp(nxti,nxtj));
			}
		}
	}
}

vector<pair<ii, ll> > vert, hor;
vi coordx, coordy;
unordered_map<ll,ll> idx, idy;

int main(){
	fastio;
	int n, m; cin>>n>>m;		
	For(i,0,n){
		ll d, u, x; cin>>d>>u>>x;
		vert.pb(mp(mp(d,u),x));
		coordx.pb(x);		
		coordy.pb(d);
		coordy.pb(u);
	}	
	For(i,0,m){
		ll y, l, r; cin>>y>>l>>r;
		hor.pb(mp(mp(l,r),y));
		coordy.pb(y);
		coordx.pb(l);
		coordx.pb(r);
	}
	coordx.pb(0);
	coordy.pb(0);

	sort(all(coordx));
	coordx.resize(unique(all(coordx))-coordx.begin());
	w = sz(coordx);
	For(i,0,w) idx[coordx[i]]=i;

	sort(all(coordy));
	coordy.resize(unique(all(coordy))-coordy.begin());
	h = sz(coordy);
	For(i,0,h) idy[coordy[i]]=i;
       if(w>=N || h>=N){
              cout<<"xd"<<endl;
       }
	w--, h--;
	For(i,0,h)
		For(j,0,w)
			area[i][j] = (coordy[i+1]-coordy[i])*(coordx[j+1]-coordx[j]);
	for(auto l: vert){
		int d = l.ff.ff, u = l.ff.ss, x = l.ss;
		int izq = idx[x]-1, der = idx[x];
		int i = idy[d];
		int fin = idy[u];
		while(i<fin){
			if(izq>=0) block[i][izq][1]=1; 
			if(der<w) block[i][der][3]=1;
			i++;
		}
	}
	for(auto elem: hor){
		int l = elem.ff.ff, r = elem.ff.ss, y = elem.ss;
		int down = idy[y]-1, up = idy[y];
		int j = idx[l];
		int fin = idx[r];
		while(j<fin){
			if(down>=0) block[down][j][0]=1; 
			if(up<h) block[up][j][2]=1;
			j++;
		}
	}
	bfs(idy[0],idx[0]);
	cout << ans << endl;
	return 0;
}


