#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  a[k] = aval;
}
template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  a[k] = aval;
  b[k] = bval;
}
template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
}
template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  for(i=sz-1;i>k;i--){
    d[i] = d[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
  d[k] = dval;
}
template<class T> int coordcomp_L(int n, T arr[], int res[] = NULL, void *mem = wmem){
  int i;
  int k = 0;
  pair<T,int> *r;
  walloc1d(&r, n, &mem);
  for(i=(0);i<(n);i++){
    r[i].first = arr[i];
    r[i].second = i;
  }
  sort(r, r+n);
  if(res != NULL){
    for(i=(0);i<(n);i++){
      if(i && r[i].first != r[i-1].first){
        k++;
      }
      res[r[i].second] = k;
    }
  }
  else{
    for(i=(0);i<(n);i++){
      if(i && r[i].first != r[i-1].first){
        k++;
      }
      arr[r[i].second] = k;
    }
  }
  return k+1;
}
struct dimcomp2{
  int B;
  dimcomp2(){
  }
  dimcomp2(int b){
    B = b;
  }
  dimcomp2(int a, int b){
    B = b;
  }
  inline void set(int b){
    B = b;
  }
  inline void set(int a, int b){
    B = b;
  }
  inline int mask(int a, int b){
    return a * B + b;
  }
  inline int operator()(int a, int b){
    return a * B + b;
  }
  inline void para(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
  inline void operator()(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
}
;
int N;
int M;
long long A[1000];
long long B[1000];
long long C[1000];
long long D[1000];
long long E[1000];
long long F[1000];
int xvs;
int yvs;
int xs;
int ys;
long long xval[3002];
long long yval[3002];
int x[3002];
int y[3002];
map<long long,int> cnvx;
map<long long,int> cnvy;
long long ccx[3002];
long long ccy[3002];
int mx;
int my;
char mp[6005][6005];
int st[40000000];
int sts;
int main(){
  int k;
  wmem = memarr;
  int i;
  int j;
  int si;
  int sj;
  int ni;
  int nj;
  int a;
  int b;
  int c;
  int dx[4] = {-1, 1, 0, 0};
  int dy[4] = {0, 0, -1, 1};
  long long res = 0;
  dimcomp2 dm;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
      rd(C[Lj4PdHRW]);
    }
  }
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(M);e98WHCEY++){
      rd(D[e98WHCEY]);
      rd(E[e98WHCEY]);
      rd(F[e98WHCEY]);
    }
  }
  xvs = yvs = 0;
  arrInsert(xvs, xvs, xval, 0LL);
  arrInsert(yvs, yvs, yval, 0LL);
  for(i=(0);i<(N);i++){
    arrInsert(xvs, xvs, xval, A[i]);
  }
  for(i=(0);i<(N);i++){
    arrInsert(xvs, xvs, xval, B[i]);
  }
  for(i=(0);i<(N);i++){
    arrInsert(yvs, yvs, yval, C[i]);
  }
  for(i=(0);i<(M);i++){
    arrInsert(xvs, xvs, xval, D[i]);
  }
  for(i=(0);i<(M);i++){
    arrInsert(yvs, yvs, yval, E[i]);
  }
  for(i=(0);i<(M);i++){
    arrInsert(yvs, yvs, yval, F[i]);
  }
  xs =coordcomp_L(xvs, xval, x);
  ys =coordcomp_L(yvs, yval, y);
  for(i=(0);i<(xvs);i++){
    cnvx[xval[i]] = x[i];
  }
  for(i=(0);i<(yvs);i++){
    cnvy[yval[i]] = y[i];
  }
  for(i=(0);i<(xvs);i++){
    ccx[x[i]] = xval[i];
  }
  for(i=(0);i<(yvs);i++){
    ccy[y[i]] = yval[i];
  }
  mx = 2*xs + 1;
  my = 2*ys + 1;
  for(k=(0);k<(N);k++){
    a = cnvx[A[k]] * 2 + 1;
    b = cnvx[B[k]] * 2 + 1;
    c = cnvy[C[k]] * 2 + 1;
    for(i=(a);i<(b+1);i++){
      mp[i][c] = 2;
    }
  }
  for(k=(0);k<(M);k++){
    a = cnvx[D[k]] * 2 + 1;
    b = cnvy[E[k]] * 2 + 1;
    c = cnvy[F[k]] * 2 + 1;
    for(i=(b);i<(c+1);i++){
      mp[a][i] = 2;
    }
  }
  dm.set(mx, my);
  si = cnvx[0] * 2 + 1;
  sj = cnvy[0] * 2 + 1;
  mp[si][sj] = 1;
  st[sts++] = dm(si, sj);
  while(sts){
    int d;
    dm(st[--sts], i, j);
    for(d=(0);d<(4);d++){
      ni = i + dx[d];
      nj = j + dy[d];
      if(ni < 0 || ni >= mx || nj < 0 || nj >= my){
        continue;
      }
      if(mp[ni][nj]){
        continue;
      }
      mp[ni][nj] = 1;
      st[sts++] = dm(ni, nj);
    }
  }
  for(i=(0);i<(mx);i+=(2)){
    for(j=(0);j<(my);j+=(2)){
      if(mp[i][j]==1){
        if(i==0 || i==mx-1 || j==0 || j==my-1){
          wt_L("INF");
          wt_L('\n');
          return 0;
        }
        res += (ccx[i/2]-ccx[i/2-1]) * (ccy[j/2]-ccy[j/2-1]);
      }
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, M;
// ll A[1000], B[1000], C[1000], D[1000], E[1000], F[1000];
// 
// int xvs, yvs, xs, ys;
// ll xval[3002], yval[3002];
// int x[3002], y[3002];
// map<ll,int> cnvx, cnvy;
// ll ccx[3002], ccy[3002];
// 
// int mx, my;
// char mp[6005][6005];
// int st[40000000], sts;
// 
// {
//   int i, j, si, sj, ni, nj, a, b, c;
//   int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
//   ll res = 0;
//   dimcomp2 dm;
//   rd(N,M,(A,B,C)(N),(D,E,F)(M));
// 
//   xvs = yvs = 0;
//   arrInsert(xvs, xvs, xval, 0LL);
//   arrInsert(yvs, yvs, yval, 0LL);
//   rep(i,N) arrInsert(xvs, xvs, xval, A[i]);
//   rep(i,N) arrInsert(xvs, xvs, xval, B[i]);
//   rep(i,N) arrInsert(yvs, yvs, yval, C[i]);
//   rep(i,M) arrInsert(xvs, xvs, xval, D[i]);
//   rep(i,M) arrInsert(yvs, yvs, yval, E[i]);
//   rep(i,M) arrInsert(yvs, yvs, yval, F[i]);
//   xs = coordcomp(xvs, xval, x);
//   ys = coordcomp(yvs, yval, y);
//   rep(i,xvs) cnvx[xval[i]] = x[i];
//   rep(i,yvs) cnvy[yval[i]] = y[i];
//   rep(i,xvs) ccx[x[i]] = xval[i];
//   rep(i,yvs) ccy[y[i]] = yval[i];
// 
//   mx = 2*xs + 1;
//   my = 2*ys + 1;
// 
//   rep(k,N){
//     a = cnvx[A[k]] * 2 + 1;
//     b = cnvx[B[k]] * 2 + 1;
//     c = cnvy[C[k]] * 2 + 1;
//     rep(i,a,b+1) mp[i][c] = 2;
//   }
//   rep(k,M){
//     a = cnvx[D[k]] * 2 + 1;
//     b = cnvy[E[k]] * 2 + 1;
//     c = cnvy[F[k]] * 2 + 1;
//     rep(i,b,c+1) mp[a][i] = 2;
//   }
// 
// 
//   dm.set(mx, my);
//   si = cnvx[0] * 2 + 1;
//   sj = cnvy[0] * 2 + 1;
//   mp[si][sj] = 1;
//   st[sts++] = dm(si, sj);
//   while(sts){
//     dm(st[--sts], i, j);
//     rep(d,4){
//       ni = i + dx[d];
//       nj = j + dy[d];
//       if(ni < 0 || ni >= mx || nj < 0 || nj >= my) continue;
//       if(mp[ni][nj]) continue;
//       mp[ni][nj] = 1;
//       st[sts++] = dm(ni, nj);
//     }
//   }
// 
//   rep(i,0,mx,2) rep(j,0,my,2) if(mp[i][j]==1){
//     if(i==0 || i==mx-1 || j==0 || j==my-1) wt("INF"), return 0;
//     res += (ccx[i/2]-ccx[i/2-1]) * (ccy[j/2]-ccy[j/2-1]);
//   }
//   wt(res);
// }


Measured memory_bytes: 77760