#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 3005;
int n, m, sh, sw;
bool z[N][N], wh[N][N], ww[N][N];
V<int> zh={0}, zw={0};
V<P<P<int, int>, int>> vh;
V<P<int, P<int, int>>> vw;
int zih(int a){ return lower_bound(all(zh), a) - zh.begin(); }
int ziw(int a){ return lower_bound(all(zw), a) - zw.begin(); }
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, n){
    int a, b, c;
    cin >> a >> b >> c;
    zh.pb(a);
    zh.pb(b);
    zw.pb(c);
    vh.pb(mp(mp(a, b), c));
  }
  FOR(i, 0, m){
    int d, e, f;
    cin >> d >> e >> f;
    zh.pb(d);
    zw.pb(e);
    zw.pb(f);
    vw.pb(mp(d, mp(e, f)));
  }
  uniq(zh);
  uniq(zw);
  sh = sz(zh);
  sw = sz(zw);
  for(auto l:vh){
    int w = ziw(l.se)+1;
    FOR(h, zih(l.fi.fi), zih(l.fi.se)) wh[h+1][w] = true;
  }
  for(auto l:vw){
    int h = zih(l.fi)+1;
    FOR(w, ziw(l.se.fi), ziw(l.se.se)) ww[h][w+1] = true;
  }
  queue<P<int, int>> q;
  {
    int h = zih(0), w = ziw(0);
    q.push(mp(h, w));
    z[h][w] = true;
  }
  ll ans = 0;
  while(!q.empty()){
    auto p = q.front();
    q.pop();
    int h = p.fi, w = p.se;
    if(h==0 || h==sh || w==0 || w==sw){
      cout << "INF" << endl;
      return 0;
    }
    ans += ll(zh[h]-zh[h-1])*(zw[w]-zw[w-1]);
    if(!ww[h+1][w] && !z[h+1][w]) z[h+1][w] = true, q.push(mp(h+1, w));
    if(!ww[h  ][w] && !z[h-1][w]) z[h-1][w] = true, q.push(mp(h-1, w));
    if(!wh[h][w+1] && !z[h][w+1]) z[h][w+1] = true, q.push(mp(h, w+1));
    if(!wh[h][w  ] && !z[h][w-1]) z[h][w-1] = true, q.push(mp(h, w-1));
  }
  cout << ans << endl;
}

Measured memory_bytes: 26680