#include <bits/stdc++.h>
using namespace std;
#define INF 1000000001
using ll=long long;

int main(){
  int N,M;
  cin>>N>>M;
  vector<ll> A(N),B(N),C(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i)>>B.at(i)>>C.at(i);
  }
  vector<ll> D(M),E(M),F(M);
  for(int j=0;j<M;j++){
    cin>>D.at(j)>>E.at(j)>>F.at(j);
  }

  vector<ll> x_coor;
  vector<ll> y_coor;
  for(int i=0;i<N;i++){
    x_coor.push_back(A.at(i));
    x_coor.push_back(B.at(i));
    y_coor.push_back(C.at(i));
  }
  for(int j=0;j<M;j++){
    x_coor.push_back(D.at(j));
    y_coor.push_back(E.at(j));
    y_coor.push_back(F.at(j));
  }
  x_coor.push_back(-INF);
  x_coor.push_back(0);
  y_coor.push_back(-INF);
  y_coor.push_back(0);

  sort(x_coor.begin(),x_coor.end());
  sort(y_coor.begin(),y_coor.end());

  map<ll,int> mx,my;
  map<int,ll> mxr,myr;
  int x_size=0;
  for(int i=0;i<x_coor.size();i++){
    if(i==0){
      mx[x_coor.at(i)]=x_size;
      mxr[x_size]=x_coor.at(i);
      x_size++;
      continue;
    }
    if(x_coor.at(i-1)!=x_coor.at(i)){
      mx[x_coor.at(i)]=x_size;
      mxr[x_size]=x_coor.at(i);
      x_size++;
    }
  }
  int y_size=0;
  for(int i=0;i<y_coor.size();i++){
    if(i==0){
      my[y_coor.at(i)]=y_size;
      myr[y_size]=y_coor.at(i);
      y_size++;
      continue;
    }
    if(y_coor.at(i-1)!=y_coor.at(i)){
      my[y_coor.at(i)]=y_size;
      myr[y_size]=y_coor.at(i);
      y_size++;
    }
  }

  vector<vector<bool>> x_u(x_size,vector<bool>(y_size,true)),x_d(x_size,vector<bool>(y_size,true)),y_u(x_size,vector<bool>(y_size,true)),y_d(x_size,vector<bool>(y_size,true));
  for(int i=0;i<N;i++){
    int y=my[C.at(i)];
    for(int x=mx[A.at(i)];x<mx[B.at(i)];x++){
      y_u.at(x).at(y-1)=false;
      y_d.at(x).at(y)=false;
    }
  }
  for(int i=0;i<M;i++){
    int x=mx[D.at(i)];
    for(int y=my[E.at(i)];y<my[F.at(i)];y++){
      x_u.at(x-1).at(y)=false;
      x_d.at(x).at(y)=false;
    }
  }

  bool inf=false;
  vector<vector<bool>> visit(x_size,vector<bool>(y_size,false));
  ll ans=0;
  queue<pair<int,int>> q;
  q.push(make_pair(mx[0],my[0]));
  visit.at(mx[0]).at(my[0])=true;
  while(!q.empty()){
    int x=q.front().first;
    int y=q.front().second;
    q.pop();
    if(x==x_size-1||y==y_size-1||x==0||y==0){
      inf=true;
      break;
    }
    ans+=(mxr[x+1]-mxr[x])*(myr[y+1]-myr[y]);
    if(x_u.at(x).at(y)){
      if(!visit.at(x+1).at(y)){
        visit.at(x+1).at(y)=true;
        q.push(make_pair(x+1,y));
      }
    }
    if(x_d.at(x).at(y)){
      if(!visit.at(x-1).at(y)){
        visit.at(x-1).at(y)=true;
        q.push(make_pair(x-1,y));
      }
    }
    if(y_u.at(x).at(y)){
      if(!visit.at(x).at(y+1)){
        visit.at(x).at(y+1)=true;
        q.push(make_pair(x,y+1));
      }
    }
    if(y_d.at(x).at(y)){
      if(!visit.at(x).at(y-1)){
        visit.at(x).at(y-1)=true;
        q.push(make_pair(x,y-1));
      }
    }
  }

  if(inf){
    cout<<"INF"<<endl;
  }else{
    cout<<ans<<endl;
  }
}
