#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAX 1010
#define MAX2 (MAX*2)
#define MAX3 (MAX*3)
#define INF 1e9

#define DOWN  1
#define UP    2
#define RIGHT 4
#define LEFT  8

int n,m;
int a[MAX][2], b[MAX][2], c[MAX][2];
int d[MAX][2], e[MAX][2], f[MAX][2];
long long x[MAX3],y[MAX3];
int xcnt,ycnt;
int result[MAX2][MAX2];

void printDir( int x, int y, int d )
{
    printf( "(%d %d) => %d", x, y, d );
    if( d & UP ) printf( " UP" );
    if( d & DOWN ) printf( " DOWN" );
    if( d & LEFT ) printf( " LEFT" );
    if( d & RIGHT ) printf( " RIGHT" );
    printf( "\n" );
}

// ソート用比較関数
int cmpfunc( const void *a, const void *b )
{
    return( *((long long *) a) - *((long long *) b) );
}

// ソートして重複を削除
int sort( long long d[],int n )
{
    int c=0;

    qsort( d, n, sizeof( long long ), cmpfunc );

    for( int i=1; i<n; i++ ) {
        if( d[i] != d[c]) {
            d[++c] = d[i];
        }
    }

    return( c+1 );
}

// 検索
int srch( int a, long long d[], int n )
{
    int l = 0;
    int r = n-1;

    while( r - l > 1 ) {
        int c = (l + r) / 2;
        if( a < d[c] ) r = c;
        else           l = c;
    }

    return( l );
}

// 四方向の壁の有無
int checkWall( int cx, int cy )
{
    int result = 0;

    for( int i=0; i<n; i++ ) {
        if( cx <  a[i][1] ) continue;
        if( cx >= b[i][1] ) continue;
        if( cy == c[i][1] ) result |= DOWN;
        if( cy == c[i][1] -1 ) result |= UP;
    }

    for( int i=0; i<m; i++ ) {
        if( cy <  e[i][1] ) continue;
        if( cy >= f[i][1] ) continue;
        if( cx == d[i][1] ) result |= LEFT;
        if( cx == d[i][1] -1 ) result |= RIGHT;
    }

//printDir( cx, cy, result );

    return( result );
}

// 
int main()
{
    long long tot = 0;

    clock_t start = clock();

    scanf( "%d %d", &n, &m );

    for( int i=0; i<n; i++ ) {
        scanf( "%d %d %d", &a[i][0], &b[i][0], &c[i][0] );
        x[xcnt++]=a[i][0];
        x[xcnt++]=b[i][0];
        y[ycnt++]=c[i][0];
    }

    for( int i=0; i<m; i++ ) {
        scanf( "%d %d %d", &d[i][0], &e[i][0], &f[i][0] );
        x[xcnt++]=d[i][0];
        y[ycnt++]=e[i][0];
        y[ycnt++]=f[i][0];
    }

    x[xcnt++] = y[ycnt++] = -INF;
    x[xcnt++] = y[ycnt++] = INF;
    x[xcnt++] = y[ycnt++] = 0;

    xcnt = sort( x, xcnt );
    ycnt = sort( y, ycnt );

//for( int i=0; i<xcnt; i++ ) printf( "x[%d] = %lld\n", i, x[i] );
//for( int i=0; i<ycnt; i++ ) printf( "y[%d] = %lld\n", i, y[i] );

    for( int i=0; i<n; i++ ) {
        a[i][1] = srch( a[i][0], x, xcnt );
        b[i][1] = srch( b[i][0], x, xcnt );
        c[i][1] = srch( c[i][0], y, ycnt );
//printf( "HORI %d: (%d %d %d)->(%d %d %d)\n", i,
//a[i][0],b[i][0],c[i][0], a[i][1],b[i][1],c[i][1] );
    }

    for( int i=0; i<m; i++ ) {
        d[i][1] = srch( d[i][0], x, xcnt );
        e[i][1] = srch( e[i][0], y, ycnt );
        f[i][1] = srch( f[i][0], y, ycnt );
//printf( "VERT %d: (%d %d %d)->(%d %d %d)\n", i,
//d[i][0],e[i][0],f[i][0], d[i][1],e[i][1],f[i][1] );
    }

    int cx = srch( 0, x, xcnt );
    int cy = srch( 0, y, ycnt );
    int cuex[2][MAX];
    int cuey[2][MAX];
    int cuenum[2] = { 1, 0 };
    int cuesel = 0;
    int cuenext;
    cuex[cuesel][0] = cx;
    cuey[cuesel][0] = cy;
    result[cx][cy] = 1;
    tot += (x[cx+1] - x[cx]) * (y[cy+1] - y[cy]);

    for( int r=1; r<100; r++ ) {

//printf( "*** %d (sel=%d,tot=%lld) ***\n", r, cuesel, tot );
        cuenext = 1 - cuesel;
        cuenum[cuenext] = 0;

        if( cuenum[cuesel] == 0 ) break;
        for( int i=0; i<cuenum[cuesel]; i++ ) {

            cx = cuex[cuesel][i];
            cy = cuey[cuesel][i];
            int wall = checkWall( cx, cy );

            // 左
            if( ! (wall & LEFT) && cx > 0 ) {
                cuex[cuenext][cuenum[cuenext]] = cx - 1;
                cuey[cuenext][cuenum[cuenext]] = cy;
                if( result[cx - 1][cy] == 0 ) {
                    cuenum[cuenext] ++;
                    result[cx - 1][cy] = r + 1;
                    tot += (x[cx] - x[cx-1]) * (y[cy+1] - y[cy]);
//printf( "left (%d %d) => %d\n", cx-1, cy, (x[cx] - x[cx-1]) * (y[cy+1] - y[cy]) );
                }
            }

            // 右
            if( ! (wall & RIGHT) && cx < xcnt ) {
                cuex[cuenext][cuenum[cuenext]] = cx + 1;
                cuey[cuenext][cuenum[cuenext]] = cy;
                if( result[cx + 1][cy] == 0 ) {
                    cuenum[cuenext] ++;
                    result[cx + 1][cy] = r + 1;
                    tot += (x[cx+2] - x[cx+1]) * (y[cy+1] - y[cy]);
//printf( "right (%d %d) => %d\n", cx+1, cy, (x[cx+1] - x[cx]) * (y[cy+1] - y[cy]) );
                }
            }

            // 下
            if( ! (wall & DOWN) && cy > 0 ) {
                cuex[cuenext][cuenum[cuenext]] = cx;
                cuey[cuenext][cuenum[cuenext]] = cy - 1;
                if( result[cx][cy - 1] == 0 ) {
                    cuenum[cuenext] ++;
                    result[cx][cy - 1] = r + 1;
                    tot += (x[cx+1] - x[cx]) * (y[cy] - y[cy-1]);
//printf( "down (%d %d) => %d\n", cx, cy-1, (x[cx+1] - x[cx]) * (y[cy] - y[cy-1]) );
                }
            }

            // 上
            if( ! (wall & UP) && cy < ycnt ) {
                cuex[cuenext][cuenum[cuenext]] = cx;
                cuey[cuenext][cuenum[cuenext]] = cy + 1;
                if( result[cx][cy + 1] == 0 ) {
                    cuenum[cuenext] ++;
                    result[cx][cy + 1] = r + 1;
                    tot += (x[cx+1] - x[cx]) * (y[cy+2] - y[cy+1]);
//printf( "up (%d %d) => %d\n", cx, cy+1, (x[cx+1] - x[cx]) * (y[cy+2] - y[cy+1]) );
                }
            }
        }

        cuesel = 1 - cuesel;
        if( cuenum[cuesel] == 0 ) break;
    }
/*
for( int j=ycnt-1; j>=0; j-- ) {
    for( int i=0; i<xcnt; i++ ) {
        printf( " %d", result[i][j] );
    }
    printf( "\n" );
}
*/

    if( result[0][0] > 0 ) puts( "INF" );
    else                   printf( "%lld\n", tot );
}
