#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < (int)v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

constexpr lint INF = 1 << 30;
const std::vector<int> dx{0, 0, 1, -1}, dy{1, -1, 0, 0};

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<std::pair<lint, std::pair<lint, lint>>> hol(n), col(m);

    std::vector<lint> xs{-INF, 0, INF}, ys{-INF, 0, INF};
    for (auto& p : hol) {
        std::cin >> p.second.first >> p.second.second >> p.first;
        ys.push_back(p.first);
        xs.push_back(p.second.first);
        xs.push_back(p.second.second);
    }
    for (auto& p : col) {
        std::cin >> p.first >> p.second.first >> p.second.second;
        xs.push_back(p.first);
        ys.push_back(p.second.first);
        ys.push_back(p.second.second);
    }

    auto revx = compress(xs);
    auto revy = compress(ys);

    // for (auto x : xs) std::cerr << x << " ";
    // std::cerr << std::endl;
    // for (auto y : ys) std::cerr << y << " ";
    // std::cerr << std::endl;

    int h = xs.size() - 1, w = ys.size() - 1;
    auto reach = vec(h, vec(w, false));
    std::queue<std::pair<int, int>> que;

    {
        auto sx = revx[0], sy = revy[0];
        for (int i = -1; i <= 0; ++i) {
            for (int j = -1; j <= 0; ++j) {
                que.emplace(sx + i, sy + j);
                reach[sx + i][sy + j] = true;
            }
        }
    }

    auto to = vec(h, vec(w, vec(4, true)));
    for (auto& p : hol) {
        p.first = revy[p.first];
        p.second.first = revx[p.second.first];
        p.second.second = revx[p.second.second];

        int y = p.first;
        for (int x = p.second.first; x < p.second.second; ++x) {
            to[x][y - 1][0] = false;
            to[x][y][1] = false;
        }
    }

    for (auto& p : col) {
        p.first = revx[p.first];
        p.second.first = revy[p.second.first];
        p.second.second = revy[p.second.second];

        int x = p.first;
        for (int y = p.second.first; y < p.second.second; ++y) {
            to[x - 1][y][2] = false;
            to[x][y][3] = false;
        }
    }

    while (!que.empty()) {
        auto [x, y] = que.front();
        que.pop();

        for (int d = 0; d < 4; ++d) {
            if (!to[x][y][d]) continue;
            auto nx = x + dx[d],
                 ny = y + dy[d];

            if (nx < 0 || h <= nx ||
                ny < 0 || w <= ny) continue;

            if (reach[nx][ny]) continue;

            reach[nx][ny] = true;
            que.emplace(nx, ny);
        }
    }

    if (reach[0][0]) {
        std::cout << "INF\n";
        return;
    }

    lint ans = 0;
    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            if (reach[x][y]) ans += (xs[x + 1] - xs[x]) * (ys[y + 1] - ys[y]);
        }
    }
    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 638924