#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int main() {
  int n,m;
  cin >> n >> m;
  int a,b,c;

  vector<tuple<int,int,int>> hs,vs;
  map<int,int> ix,iy;
  ix[0] = iy[0] = 0;
  rep(i,n){
    cin >> a >> b >> c;
    ix[a] = ix[b] = iy[c] = 0;
    hs.emplace_back(a,b,c);
  }
  rep(i,m){
    cin >> a >> b >> c;
    ix[a] = iy[b] = iy[c] = 0;
    vs.emplace_back(a,b,c);
  }
  vector<int> xs,ys;
  for(auto& i:ix){
    i.second = xs.size();
    xs.push_back(i.first);
  }
  for(auto& i:iy){
    i.second = ys.size();
    ys.push_back(i.first);
  }
  int h = xs.size()*2, w = ys.size()*2;
  vector<vector<int>> d(h,vector<int>(w));
  rep(i,n){
    int a,b,c; tie(a,b,c) = hs[i];
    a = ix[a]*2; 
    b = ix[b]*2;
    c = iy[c]*2;
    for(int x = a; x<=b; ++x) d[x][c] = -1;
  }
  rep(i,m){
    int a,b,c; tie(a,b,c) = vs[i];
    a = ix[a]*2; 
    b = iy[b]*2;
    c = iy[c]*2;
    for(int y = b; y<=c; ++y) d[a][y] = -1;
  }
  queue<P> q;
  auto push = [&](int x,int y){
    if(x<0||h<=x||y<0||w<=y) return;
    if(d[x][y]!=0) return;
    d[x][y] = 1;
    q.emplace(x,y);
  };
  push(ix[0]*2,iy[0]*2);
  while(!q.empty()) {
    P p = q.front(); q.pop();
    int x = p.first, y = p.second;
    rep(i,4) push(x+dx[i],y+dy[i]);
  }

  ll ans = 0;
  rep(x,h)rep(y,w){
    if(d[x][y]!=1) continue;
    if(x==0||h-1==x||y==0||w-1==y) {
      cout << "INF" << endl;
      return 0;
    }
    if(x%2==0||y%2==0) continue;
    ans += ll(xs[x/2+1]-xs[x/2])*ll(ys[y/2+1]-ys[y/2]);
  }
  cout << ans << endl;
}
