/*

*/

#include<bits/stdc++.h>
using namespace std;
typedef pair<long,long>P;
int main(){
  long N,M;cin>>N>>M;
  vector<long>A(N),B(N),C(N),D(M),E(M),F(M);
  set<long>xs,ys;
  for(long i=0;i<N;i++){
    cin>>A[i]>>B[i]>>C[i];
    xs.insert(A[i]);
    xs.insert(B[i]);
    ys.insert(C[i]);
  }
  for(long i=0;i<M;i++){
    cin>>D[i]>>E[i]>>F[i];
    ys.insert(E[i]);
    ys.insert(F[i]);
    xs.insert(D[i]);
  }
  vector<long>X,Y;//id->実座標
  map<long,long>IX,IY;// 実座標->id
  X=vector<long>(xs.begin(),xs.end());sort(X.begin(),X.end());
  Y=vector<long>(ys.begin(),ys.end());sort(Y.begin(),Y.end());
  for(long i=0;i<X.size();i++)IX[X[i]]=i;
  for(long i=0;i<Y.size();i++)IY[Y[i]]=i;
  
  vector<vector<long>>R(2*X.size()+1,vector<long>(2*Y.size()+1));
  //実際の白黒
  vector<vector<long>>Q(2*X.size()+1,vector<long>(2*Y.size()+1));
  //面積
  
  for(long i=0;i<N;i++){
    for(long j=IX[A[i]]*2+1;j<=IX[B[i]]*2+1;j++)R[j][IY[C[i]]*2+1]=1;
  }
  for(long i=0;i<M;i++){
    for(long j=IY[E[i]]*2+1;j<=IY[F[i]]*2+1;j++)R[IX[D[i]]*2+1][j]=1;
  }
  
  for(long i=0;i<X.size()-1;i++)for(long j=0;j<Y.size()-1;j++){
    Q[i*2+2][j*2+2]=(X[i+1]-X[i])*(Y[j+1]-Y[j]);
  }
  long W=X.size()*2+1;
  long H=Y.size()*2+1;
  long sx=X.size()-1;while(X[sx]>0)sx--;
  long sy=Y.size()-1;while(Y[sy]>0)sy--;
  queue<P>q;q.push(P(
    (X[sx]==0?2*sx+1:2*sx+2),
    (Y[sy]==0?2*sy+1:2*sy+2))
  );
  vector<vector<long>>U(2*X.size()+1,vector<long>(2*Y.size()+1));
  U[(X[sx]==0?2*sx+1:2*sx+2)][(Y[sy]==0?2*sy+1:2*sy+2)]=1;
  
  
  while(q.size()){
    P p=q.front();q.pop();
    if(p.first>0&&
       R[p.first-1][p.second]==0&&
       U[p.first-1][p.second]==0){
      U[p.first-1][p.second]=1;
      q.push(P(p.first-1,p.second));
    }
    if(p.first<W-1&&
       R[p.first+1][p.second]==0&&
       U[p.first+1][p.second]==0){
      U[p.first+1][p.second]=1;
      q.push(P(p.first+1,p.second));
    }
    if(p.second>0&&
       R[p.first][p.second-1]==0&&
       U[p.first][p.second-1]==0){
      U[p.first][p.second-1]=1;
      q.push(P(p.first,p.second-1));
    }
    if(p.second<H-1&&
       R[p.first][p.second+1]==0&&
       U[p.first][p.second+1]==0){
      U[p.first][p.second+1]=1;
      q.push(P(p.first,p.second+1));
    }  
  }
  if(U[0][0]==1){cout<<"INF";return 0;}
  long ans=0;
  for(long i=0;i<W;i++)for(long j=0;j<H;j++)if(U[i][j])
    ans+=Q[i][j];
  cout<<ans;
    
}