#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> ver_lines(n), hor_lines(m);
    vector<int> X, Y;
    X.push_back(0);
    Y.push_back(0);
    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        ver_lines[i] = make_tuple(a, b, c);
        X.push_back(a);
        X.push_back(b);
        Y.push_back(c);
    }
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        hor_lines[i] = make_tuple(a, b, c);
        X.push_back(a);
        Y.push_back(b);
        Y.push_back(c);
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());
    map<int, int> mp_x, mp_y;
    rep(i, X.size()) {
        mp_x[X[i]] = i;
    }
    rep(i, Y.size()) {
        mp_y[Y[i]] = i;
    }
    int h = X.size() * 2;
    int w = Y.size() * 2;
    vector<vector<int>> F(h, vector<int>(w, 0));
    rep(i, n) {
        int a, b, c;
        tie(a, b, c) = ver_lines[i];
        a = mp_x[a] * 2;
        b = mp_x[b] * 2;
        c = mp_y[c] * 2;
        for (int j = a; j <= b; ++j) F[j][c] = -1;
    }
    rep(i, m) {
        int a, b, c;
        tie(a, b, c) = hor_lines[i];
        a = mp_x[a] * 2;
        b = mp_y[b] * 2;
        c = mp_y[c] * 2;
        for (int j = b; j <= c; ++j) F[a][j] = -1;
    }
    queue<P> q;
    int sx = mp_x[0]*2, sy = mp_y[0]*2;
    q.emplace(sx, sy);
    F[sx][sy] = 1;
    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (F[nx][ny] != 0) continue;
            F[nx][ny] = 1;
            q.emplace(nx, ny);
        }
    }
    ll ans = 0;
    rep(i, h) rep(j, w) {
        if (F[i][j] != 1) continue;
        if (i == 0 || i == h-1 || j == 0 || j == w-1) {
            cout << "INF" << endl;
            return 0;
        }
        if (i % 2 == 0 || j % 2 == 0) continue;
        ll x = X[i/2+1] - X[i/2];
        ll y = Y[j/2+1] - Y[j/2];
        ans += x * y;
    }
    cout << ans << endl;
    return 0;
}