#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll lowerid(vll& V, ll val) {
    return lower_bound(V.begin(), V.end(), val) - V.begin();
}

void eraseMultiple(vll& V) {
    sort(V.begin(), V.end());
    V.erase(unique(V.begin(), V.end()), V.end());
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vll vert, hori;
    ll A[N], B[N], C[N], D[M], E[M], F[M];
    REP(i, 0, N) {
        cin >> A[i] >> B[i] >> C[i];
        vert.push_back(A[i]);
        vert.push_back(B[i]);
        hori.push_back(C[i]);
    }
    REP(i, 0, M) {
        cin >> D[i] >> E[i] >> F[i];
        vert.push_back(D[i]);
        hori.push_back(E[i]);
        hori.push_back(F[i]);
    }
    vert.push_back(0);
    vert.push_back(inf);
    vert.push_back(-inf);
    hori.push_back(0);
    hori.push_back(inf);
    hori.push_back(-inf);
    eraseMultiple(vert);
    eraseMultiple(hori);
    // REP(i, 0, vert.size()) {
    //     cout << vert[i] << " ";
    // }
    // cout << endl;
    // REP(i, 0, hori.size()) {
    //     cout << hori[i] << " ";
    // }
    // cout << endl;
    V<vll> vertmat, horimat;
    vertmat = V<vll>(vert.size(), vll(hori.size(), 0));
    horimat = V<vll>(vert.size(), vll(hori.size(), 0));
    V<V<bool>> used(vert.size(), V<bool>(hori.size(), false));
    REP(i, 0, N) {
        vertmat[lowerid(vert, A[i])][lowerid(hori, C[i])]++;
        vertmat[lowerid(vert, B[i])][lowerid(hori, C[i])]--;
    }
    REP(i, 0, M) {
        horimat[lowerid(vert, D[i])][lowerid(hori, E[i])]++;
        horimat[lowerid(vert, D[i])][lowerid(hori, F[i])]--;
    }
    REP(i, 1, vert.size() - 1) {
        REP(j, 1, hori.size() - 1) {
            vertmat[i][j] += vertmat[i - 1][j];
            horimat[i][j] += horimat[i][j - 1];
        }
    }
    // REP(i, 0, vert.size()) {
    //     REP(j, 0, hori.size()) {
    //         cout << vertmat[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << "aaa" << endl;
    // REP(i, 0, vert.size()) {
    //     REP(j, 0, hori.size()) {
    //         cout << horimat[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << "aaa" << endl;
    queue<plglg> que;
    que.push(plglg(lowerid(vert, 0), lowerid(hori, 0)));
    ll ans = 0;
    while (!que.empty()) {
        plglg p = que.front();
        que.pop();
        ll x = p.first;
        ll y = p.second;
        // cout << x << " " << y << endl;
        if (x == 0 || x == vert.size() - 1 || y == 0 || y == hori.size() - 1) {
            cout << "INF" << endl;
            return 0;
        }
        if (!used[x][y]) {
            used[x][y] = true;
            ans += (vert[x + 1] - vert[x]) * (hori[y + 1] - hori[y]);
            if (!horimat[x][y]) {
                que.push(plglg(x - 1, y));
            }
            if (!horimat[x + 1][y]) {
                que.push(plglg(x + 1, y));
            }
            if (!vertmat[x][y]) {
                que.push(plglg(x, y - 1));
            }
            if (!vertmat[x][y + 1]) {
                que.push(plglg(x, y + 1));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 146088