#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* [💭] [💡] [🎈] */

int _a[1000], _b[1000], _c[1000], _d[1000], _e[1000], _f[1000];
vector<int> xs, ys;

int getidx_x(int x) {
    return lower_bound(xs.begin(), xs.end(), x) - xs.begin();
}

int getidx_y(int y) {
    return lower_bound(ys.begin(), ys.end(), y) - ys.begin();
}

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

bitset<7000> bo[7000], vis[7000];

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    xs.emplace_back(-1.5e9);
    ys.emplace_back(-1.5e9);

    xs.emplace_back(0);
    ys.emplace_back(0);
    for (int i = 0; i < n; i++) {
        cin >> _a[i] >> _b[i] >> _c[i];
        xs.emplace_back(_a[i]), xs.emplace_back(_b[i]), ys.emplace_back(_c[i]);
    }
    for (int i = 0; i < m; i++) {
        cin >> _d[i] >> _e[i] >> _f[i];
        xs.emplace_back(_d[i]), ys.emplace_back(_e[i]), ys.emplace_back(_f[i]);
    }
    sort(xs.begin(), xs.end()), sort(ys.begin(), ys.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end()), ys.erase(unique(ys.begin(), ys.end()), ys.end());

    for (int i = 0; i < n; i++) {
        int az = getidx_x(_a[i]), bz = getidx_x(_b[i]), cz = getidx_y(_c[i]);
        for (int j = az * 2 - 1; j < bz * 2; j++) bo[j][cz * 2 - 1] = true;
    }
    for (int i = 0; i < m; i++) {
        int dz = getidx_x(_d[i]), ez = getidx_y(_e[i]), fz = getidx_y(_f[i]);
        for (int j = ez * 2 - 1; j < fz * 2; j++) bo[dz * 2 - 1][j] = true;
    }

    int s = getidx_x(0) * 2 - 1, e = getidx_y(0) * 2 - 1;

    bool inf = false;

    ll sum = 0;
    queue<pii> q;
    vis[s][e] = true;
    q.emplace(s, e);
    while (q.size()) {
        int x = q.front().first, y = q.front().second;
        if (x == 6999 || y == 6999 || !x || !y) {
            inf = true;
            break;
        }
        q.pop();
        if (!(x % 2) && !(y % 2)) {
            int i = x / 2, j = y / 2;
            sum += (ll)(xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]);
        }
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d];
            int ny = y + dy[d];
            if (7000 <= nx || nx < 0) continue;
            if (7000 <= ny || ny < 0) continue;
            if (vis[nx][ny]) continue;
            if (bo[nx][ny]) continue;
            vis[nx][ny] = true;
            q.emplace(nx, ny);
        }
    }

    if (!inf) {
        cout << sum;
    } else {
        cout << "INF";
    }

    return 0;
}

/*
 *
2 2
-1 1 -1
-1 1 1
-1 -1 1
1 -1 1
 */