#include <bits/stdc++.h>
using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll n,m;
ll a[1010],b[1010],c[1010],d[1010],e[1010],f[1010];

bool line[6060][6060];
bool dp[6060][6060];

void solve(){
	cin>>n>>m;

	map<ll,ll> mpx,mpy;
	mpx[0]++;
	mpy[0]++;
	REP(i,n){
		cin>>a[i]>>b[i]>>c[i];
		mpx[a[i]]++;
		mpx[b[i]]++;
		mpy[c[i]]++;
	}
	REP(i,m){
		cin>>d[i]>>e[i]>>f[i];
		mpx[d[i]]++;
		mpy[e[i]]++;
		mpy[f[i]]++;
	}

	Array xs,ys;
	for(auto& i:mpx){
		i.second=xs.size();
		xs.push_back(i.first);
	}
	for(auto& i:mpy){
		i.second=ys.size();
		ys.push_back(i.first);
	}

	REP(i,n){
		ll aa=mpx[a[i]];
		ll bb=mpx[b[i]];
		ll cc=mpy[c[i]];
		rep(x,aa*2,bb*2+1) line[x][cc*2]=true;
	}
	REP(i,m){
		ll dd=mpx[d[i]];
		ll ee=mpy[e[i]];
		ll ff=mpy[f[i]];
		rep(y,ee*2,ff*2+1) line[dd*2][y]=true;
	}

	

	ll dx[4]={0,0,1,-1};
	ll dy[4]={1,-1,0,0};
	
	ll mx=xs.size()*2;
	ll my=ys.size()*2;

	ll ans=0;

	queue<pair<int,int>> que;
	que.push({mpx[0]*2,mpy[0]*2});
	dp[mpx[0]*2][mpy[0]*2]=true;

	while(que.size()){
		auto [x,y] = que.front();
		que.pop();
		if(x==0 || x==mx-1 || y==0 || y==my-1){
			cout<<"INF"<<en;
			return;
		}
		if(x%2==1 && y%2==1){
			ans += (xs[x/2+1]-xs[x/2])*(ys[y/2+1]-ys[y/2]);
		}

		REP(v,4){
			ll nx=x+dx[v];
			ll ny=y+dy[v];
			if(nx<0 || nx>=mx || ny<0 || ny>=my) continue;
			if(line[nx][ny]) continue;
			if(dp[nx][ny]) continue;
			dp[nx][ny]=true;
			que.push({nx,ny});
		}
	}
	cout<<ans<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}