#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[3005][3005];
int flag1[3005][3005];
int vis[3005][3005];

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

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

        int k;
        for (k = a[i]; k < b[i]; k++) {
            flag1[k][c[i]] = 1;
        }
    }
    for (i = 0; i < m; i++) {
        d[i] = mp0[d[i]];
        e[i] = mp1[e[i]];
        f[i] = mp1[f[i]];

        int k;
        for (k = e[i]; k < f[i]; k++) {
            flag0[d[i]][k] = 1;
        }
    }

    ll ans = 0;
    queue<int> que;
#define P(i,j) ((i)*3000+(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 / 3000;
        int y = curr % 3000;        
        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 >= 3000 || y2<0 || y2>=3000) {
                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: 76172