#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct UnionFind {
    UnionFind(int n) : p(n, -1), s(n, 0) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
        if (s[u] == 0 || s[v] == 0) s[u] = 0; else s[u] += s[v];
    }
    vector<int> p;
    vector<ll> s;
};

struct P {
    int a, b, c;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n[2];
    for (int h = 0; h < 2; h++) {
        cin >> n[h];
    }

    vector<P> p[2];
    vector<int> x[2];
    int k[2];
    int s[2];

    for (int h = 0; h < 2; h++) {
        p[h].resize(n[h]);
        for (auto& [a, b, c] : p[h]) {
            cin >> a >> b >> c;
            x[0].push_back(a);
            x[h].push_back(b);
            x[1].push_back(c);
        }
        x[h].push_back(0);
    }
    for (int h = 0; h < 2; h++) {
        sort(x[h].begin(), x[h].end());
        k[h] = unique(x[h].begin(), x[h].end()) - x[h].begin();
        x[h].resize(k[h]);
    }
    for (int h = 0; h < 2; h++) {
        for (auto& [a, b, c] : p[h]) {
            a = lower_bound(x[0].begin(), x[0].end(), a) - x[0].begin();
            b = lower_bound(x[h].begin(), x[h].end(), b) - x[h].begin();
            c = lower_bound(x[1].begin(), x[1].end(), c) - x[1].begin();
        }
        s[h] = lower_bound(x[h].begin(), x[h].end(), 0) - x[h].begin();
    }
    
    vector<vector<char>> u(x[0].size(), vector<char>(x[1].size(), 0));
    for (const auto& [a, b, c] : p[0]) {
        for (int i = a; i < b; i++) {
            u[i][c] |= 1;
        }
    }
    for (const auto& [a, b, c] : p[1]) {
        for (int j = b; j < c; j++) {
            u[a][j] |= 2;
        }
    }

    UnionFind uf(k[0] * k[1]);
    for (int i = 0; i < k[0]; i++) {
        for (int j = 0; j < k[1]; j++) {
            int t = k[1] * i + j;
            if (i < k[0] - 1 && j < k[1] - 1) {
                uf.s[t] = (ll)(x[0][i + 1] - x[0][i]) * (x[1][j + 1] - x[1][j]);
            }
            if (!(u[i][j] & 1)) {
                if (j == 0) uf.s[t] = 0; else uf.unite(t, t - 1);
            }
            if (!(u[i][j] & 2)) {
                if (i == 0) uf.s[t] = 0; else uf.unite(t, t - k[1]);
            }
        }
    }

    ll r = uf.s[uf.root(k[1] * s[0] + s[1])];
    if (r == 0) {
        cout << "INF" << endl;
    } else {
        cout << r << endl;
    }

    return 0;
}