#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

int flag0[3020][3020];
int flag1[3020][3020];
int vis[3020][3020];

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

void solve()
{
    int n, m;
    scanf("%d%d", &n, &m);
    vector<ll> a(n), b(n), c(n), d(m), e(m), f(m);
    map<ll, int> mp0, mp1;
    mp0[0] = 0;
    mp1[0] = 0;
    int i;
    for (i = 0; i < n; i++) {
        scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
        mp0[a[i]] = 0;
        mp0[b[i]] = 0;
        mp1[c[i]] = 0;
    }
    for (i = 0; i < m; i++) {
        scanf("%lld%lld%lld", &d[i], &e[i], &f[i]); 
        mp0[d[i]] = 0;
        mp1[e[i]] = 0;
        mp1[f[i]] = 0;
    }
    vector<ll> diff0, diff1;
    {
        int cnt = 0;
        auto it = mp0.begin();
        ll prev = 0;
        for (; it != mp0.end(); ++it) {
            ll curr = it->first;
            if (cnt > 0) diff0.push_back(curr - prev);
            it->second = cnt;
            cnt++;
            prev = curr;
        }
    }
    {
        int cnt = 0;
        auto it = mp1.begin();
        ll prev = 0;
        for (; it != mp1.end(); ++it) {
            ll curr = it->first;
            if (cnt > 0) diff1.push_back(curr - prev);
            it->second = cnt;
            cnt++;
            prev = curr;
        }
    }

    for (i = 0; i < n; i++) {
        int aa = mp0[a[i]];
        int bb = mp0[b[i]];
        int cc = mp1[c[i]];

        int k;
        for (k = aa; k < bb; k++) {
            flag1[k][cc] = 1;
        }
    }
    for (i = 0; i < m; i++) {
        int dd = mp0[d[i]];
        int ee = mp1[e[i]];
        int ff = mp1[f[i]];

        int k;
        for (k = ee; k < ff; k++) {
            flag0[dd][k] = 1;
        }
    }

    ll ans = 0;
    queue<int> que;
#define P(i,j) ((i)*3010+(j))
    int sx = mp0[0], sy = mp1[0];
    que.push(P(sx,sy));
    vis[sx][sy] = 1;
    ans += (ll)diff0[sx] * diff1[sy];
    while (!que.empty()) {
        int curr = que.front();
        que.pop();
        int x = curr / 3010;
        int y = curr % 3010;        
        int k;
        for (k = 0; k < 4; k++) {
            int x2 = x + dx[k], y2 = y + dy[k];
            if (k == 0) {
                if (flag0[x + 1][y]) continue;
            }
            else if(k==1) {
                if (flag0[x][y]) continue;
            }
            else if (k == 2) {
                if (flag1[x][y+1]) continue;
            }
            else {
                if (flag1[x][y]) continue;
            }
            if (x2 < 0 || x2 >= 3010 || y2<0 || y2>=3010) {
                printf("INF\n"); return;
            }
            if (vis[x2][y2] == 0) {
                que.push(P(x2, y2));
                vis[x2][y2] = 1;
                ans += (ll)diff0[x2] * diff1[y2];
            }
        }
    }
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 76756