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

struct line{
  ll a;
  ll b;
  ll c;
};

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
  int n,m;
  cin>>n>>m;
  vector<ll> x;
  vector<ll> y;
  map<ll,int> mx;
  map<ll,int> my;
  x.push_back(-1e9-1e6);
  x.push_back(1e9+1e6);
  y.push_back(-1e9-1e6);
  y.push_back(1e9+1e6);
  vector<line> vec(n);
  vector<line> vecb(m);
  for(int i=0;i<n;i++){
    cin>>vec[i].a>>vec[i].b>>vec[i].c;
    if(mx[vec[i].a]==0){
      x.push_back(vec[i].a);
      mx[vec[i].a]++;
    }
    if(mx[vec[i].b]==0){
      x.push_back(vec[i].b);
      mx[vec[i].b]++;
    }
    if(my[vec[i].c]==0){
      y.push_back(vec[i].c);
      my[vec[i].c]++;
    }
  }
  for(int i=0;i<m;i++){
    cin>>vecb[i].a>>vecb[i].b>>vecb[i].c;
    if(mx[vecb[i].a]==0){
      x.push_back(vecb[i].a);
      mx[vecb[i].a]++;
    }
    if(my[vecb[i].b]==0){
      y.push_back(vecb[i].b);
      my[vecb[i].b]++;
    }
    if(my[vecb[i].c]==0){
      y.push_back(vecb[i].c);
      my[vecb[i].c]++;
    }
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  map<int,ll> wherex;
  map<int,ll> wherey;
  int xsize=x.size();
  int ysize=y.size();
  for(int i=0;i<xsize;i++){
    //cout<<x[i]<<" ";
    wherex[x[i]]=i;
  }
  //cout<<endl;
  for(int i=0;i<ysize;i++){
    //cout<<y[i]<<" ";
    wherey[y[i]]=i;
  }
  //cout<<endl;
  
  vector<vector<ll>> grid(x.size()-1,vector<ll>(y.size()-1));  
  queue<pair<int,int>> que;
  
  vector<vector<int>> gridx(x.size()-1,vector<int>(y.size()));//縦線
  vector<vector<int>> gridy(x.size(),vector<int>(y.size()-1));//横線
  
  for(int i=0;i<xsize-1;i++){
    for(int j=0;j<ysize;j++){
      gridx[i][j]=0;
    }
  }
  for(int i=0;i<xsize;i++){
    for(int j=0;j<ysize-1;j++){
      gridy[i][j]=0;
    }
  }
  
  for(int i=0;i<n;i++){
    gridx[wherex[vec[i].a]][wherey[vec[i].c]]++;
    gridx[wherex[vec[i].b]][wherey[vec[i].c]]--;
  }
  for(int i=1;i<xsize-1;i++){
    for(int j=0;j<ysize;j++){
      gridx[i][j]+=gridx[i-1][j];
    }
  }
  
  for(int i=0;i<m;i++){
    gridy[wherex[vecb[i].a]][wherey[vecb[i].b]]++;
    gridy[wherex[vecb[i].a]][wherey[vecb[i].c]]--;
  }
  for(int i=0;i<xsize;i++){
    for(int j=1;j<ysize-1;j++){
      gridy[i][j]+=gridy[i][j-1];
    }
  }
  
  
  for(int i=0;i<x.size()-1;i++){
    for(int j=0;j<y.size();j++){
      //cout<<gridx[i][j]<<" ";
    }
    //cout<<endl;
  }
  //cout<<endl;
  for(int i=0;i<x.size();i++){
    for(int j=0;j<y.size()-1;j++){
      //cout<<gridy[i][j]<<" ";
    }
    //cout<<endl;
  }
  //cout<<endl;
  
  
  
  for(int i=0;i<xsize-1;i++){
    for(int j=0;j<ysize-1;j++){
      grid[i][j]=0;
      if(x[i]<=0&&0<=x[i+1]&&y[j]<=0&&0<=y[j+1]){
        grid[i][j]++;
        que.push(make_pair(i,j));
      }
      //cout<<grid[i][j];
    }
    //cout<<endl;
  }
  
  while(!que.empty()){
    pair<int,int> front=que.front();
    int nowx=front.first;
    int nowy=front.second;
    que.pop();
    for(int i=0;i<4;i++){
      int next_x=nowx+dx[i];
      int next_y=nowy+dy[i];
      if(next_x<0||next_x>=x.size()-1||next_y<0||next_y>=y.size()-1)continue;
      if (grid[next_x][next_y]==0){
        if(nowx==next_x){
          if(nowy<next_y){
            if(gridx[next_x][next_y]!=0){
              continue;
            }
          }
          else{
            if(gridx[nowx][nowy]!=0){
              continue;
            }
          }
        }
        if(nowy==next_y){
          if(nowx<next_x){
            if(gridy[next_x][next_y]!=0){
              continue;
            }
          }
          else{
            if(gridy[nowx][nowy]!=0){
              continue;
            }
          }
        }
        que.push(make_pair(next_x,next_y));
        grid[next_x][next_y]=1;
      }
    }
  }
  
  if(grid[0][0]!=0){
    cout<<"INF"<<endl;
    return 0;
  }
  
  for(int i=0;i<x.size()-1;i++){
    for(int j=0;j<y.size()-1;j++){
      //cout<<grid[i][j]<<" ";
    }
    //cout<<endl;
  }
  
  ll ans=0;
  for(int i=0;i<x.size()-1;i++){
    for(int j=0;j<y.size()-1;j++){
      ll size=x[i+1]-x[i];
      size*=y[j+1]-y[j];
      //cout<<size<<" ";
      if(grid[i][j]!=0){
        ans+=size;
      }
      //cout<<ans<<endl;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 145276