#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <numeric>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mod = 998244353;

#define bs(n) (1ll<<(ll)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define rrep(i, n) for(ll (i) = 1;(i) <= (n);(i)++)

typedef struct {
    int x1, x2, y1, y2;
} seg;

char b[2][4000][4000], c[4000][4000];

int main() {
    int n, m;
    vector<seg> abc, def;
    set<int> vx, vy;
    vx.insert(0);
    vy.insert(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        seg w;
        int a, b, c;
        cin >> a >> b >> c;
        w.x1 = a;
        w.x2 = b;
        w.y1 = w.y2 = c;
        abc.push_back(w);
    }
    for (int i = 0; i < m; i++) {
        seg w;
        int d, e, f;
        cin >> d >> e >> f;
        w.x1 = w.x2 = d;
        w.y1 = e;
        w.y2 = f;
        def.push_back(w);
    }
    for (auto e:{&abc, &def}) {
        for (auto &f:*e) {
            vx.insert(f.x1);
            vx.insert(f.x2);
            vy.insert(f.y1);
            vy.insert(f.y2);
        }
    }
    vector<int> vvx, vvy;
    for (auto &e:vx) vvx.push_back(e);
    for (auto &e:vy) vvy.push_back(e);
    auto gcx = [&vvx](int x) {
        return lower_bound(vvx.begin(), vvx.end(), x) - vvx.begin() + 10;
    };
    auto gcy = [&vvy](int y) {
        return lower_bound(vvy.begin(), vvy.end(), y) - vvy.begin() + 10;
    };
    auto grx = [&vvx](int x) {
        return vvx[x-10];
    };
    auto gry = [&vvy](int y) {
        return vvy[y-10];
    };
    vector<seg> abc2, def2;
    for (auto &e:{make_pair(&abc, &abc2), make_pair(&def, &def2)}) {
        for (auto &f:*e.first) {
            seg w;
            w.x1 = gcx(f.x1);
            w.x2 = gcx(f.x2);
            w.y1 = gcy(f.y1);
            w.y2 = gcy(f.y2);
            e.second->push_back(w);
        }
    }
    memset(b, 0, 2 * 4000 * 4000);
    memset(c, 0, 4000 * 4000);
    for (auto &e:abc2) {
        for (int x = e.x1; x < e.x2; x++) {
            b[0][x][e.y1] = 1;
        }
    }
    for (auto &e:def2) {
        for (int y = e.y1; y < e.y2; y++) {
            b[1][e.x1][y] = 1;
        }
    }
    queue<pair<int, int>> q;
    q.push(make_pair(gcx(0), gcy(0)));
    while (!q.empty()) {
        auto cur = q.front();
        q.pop();
        c[cur.first][cur.second] = 1;
        if (cur.second != 0 && b[0][cur.first][cur.second] == 0 && c[cur.first][cur.second - 1] == 0) {
            q.push(make_pair(cur.first, cur.second - 1));
            c[cur.first][cur.second - 1] = 1;
        }
        if (cur.second != 3990 && b[0][cur.first][cur.second + 1] == 0 && c[cur.first][cur.second + 1] == 0) {
            q.push(make_pair(cur.first, cur.second + 1));
            c[cur.first][cur.second + 1] = 1;
        }
        if (cur.first != 0 && b[1][cur.first][cur.second] == 0 && c[cur.first - 1][cur.second] == 0) {
            q.push(make_pair(cur.first - 1, cur.second));
            c[cur.first - 1][cur.second] = 1;
        }
        if (cur.first != 3990 && b[1][cur.first + 1][cur.second] == 0 && c[cur.first + 1][cur.second] == 0) {
            q.push(make_pair(cur.first + 1, cur.second));
            c[cur.first + 1][cur.second] = 1;
        }
    }
    if (c[0][0] == 1) {
        cout << "INF\n";
        return 0;
    }
    ll r = 0;
    for (int x = 0; x < 4000; x++) {
        for (int y = 0; y < 4000; y++) {
            if (c[x][y] == 1) {
                ll x1 = grx(x), x2 = grx(x + 1), y1 = gry(y), y2 = gry(y + 1);
                r += (x2 - x1) * (y2 - y1);
            }
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 50916