#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <tuple>
#include <utility>
#include <algorithm>
#include <limits>
using i64 = long long;

int main() {
    constexpr i64 inf = std::numeric_limits<i64>::max() / 2;
    int n, m;
    std::cin >> n >> m;
    std::vector<i64> xs, ys;
    std::vector<std::tuple<i64, i64, i64>> evx, evy;
    for (int i = 0; i < n; i++) {
        i64 a, b, c;
        std::cin >> a >> b >> c;
        xs.push_back(a);
        xs.push_back(b);
        ys.push_back(c);
        evx.emplace_back(c, a, b);
    }
    for (int i = 0; i < m; i++) {
        i64 d, e, f;
        std::cin >> d >> e >> f;
        xs.push_back(d);
        ys.push_back(e);
        ys.push_back(f);
        evy.emplace_back(d, e, f);
    }

    std::sort(xs.begin(), xs.end());
    xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
    std::sort(ys.begin(), ys.end());
    ys.erase(std::unique(ys.begin(), ys.end()), ys.end());

    const int cx = xs.size(), cy = ys.size();

    std::vector ex(cx, std::vector<int>(cy + 1)), ey(cy, std::vector<int>(cx + 1));
    for (const auto [c, a, b] : evx) {
        const int li = std::lower_bound(xs.begin(), xs.end(), a) - xs.begin(),
            ui = std::lower_bound(xs.begin(), xs.end(), b) - xs.begin(),
            j = std::lower_bound(ys.begin(), ys.end(), c) - ys.begin();
        ey[j][li]++;
        ey[j][ui]--;
    }

    for (const auto [d, e, f] : evy) {
        const int li = std::lower_bound(ys.begin(), ys.end(), e) - ys.begin(),
            ui = std::lower_bound(ys.begin(), ys.end(), f) - ys.begin(),
            j = std::lower_bound(xs.begin(), xs.end(), d) - xs.begin();
        ex[j][li]++;
        ex[j][ui]--;
    }

    for (auto &v : ex) for (int i = 1; i <= cy; i++) v[i] += v[i - 1];
    for (auto &v : ey) for (int i = 1; i <= cx; i++) v[i] += v[i - 1];

    int s = -1;
    auto get = [=](const int x, const int y) {
        return (cy + 1) * x + y;
    };
    std::vector<std::vector<int>> g((cx + 1) * (cy + 1));
    for (int i = 1; i < cx; i++) for (int j = 1; j < cy; j++) {
        const int v = get(i, j);
        if (!ex[i - 1][j - 1]) g[v].push_back(get(i - 1, j));
        if (!ex[i][j - 1]) g[v].push_back(get(i + 1, j));
        if (!ey[j - 1][i - 1]) g[v].push_back(get(i, j - 1));
        if (!ey[j][i - 1]) g[v].push_back(get(i, j + 1));
        const i64 lx = xs[i - 1], ux = xs[i], ly = ys[j - 1], uy = ys[j];
        // fprintf(stderr, "i = %d, j = %d, [%lld, %lld) * [%lld, %lld)\n", i, j, lx, ux, ly, uy);
        if (lx <= 0 && 0 <= ux && ly <= 0 && 0 <= uy) s = v;
    }

    i64 ret = 0;
    std::deque<int> q { s };
    std::vector<int> done(g.size());

    if (s < 0) {
        printf("INF\n");
        return 0;
    }

    done[s] = 1;
    while (!q.empty()) {
        const int v = q.front();
        q.pop_front();
        const int xi = v / (cy + 1), yi = v % (cy + 1);
        if (xi == 0 || xi == cx || yi == 0 || yi == cy) {
            printf("INF\n");
            return 0;
        }
        const i64 dx = xs[xi] - xs[xi - 1], dy = ys[yi] - ys[yi - 1];
        ret += dx * dy;
        for (const int to : g[v]) {
            if (done[to]) continue;
            done[to] = 1;
            q.push_back(to);
        }
    }

    if (ret >= inf) printf("INF\n");
    else printf("%lld\n", ret);

    return 0;
}


Measured memory_bytes: 601232