#include <bits/stdc++.h>

typedef long long ll ;
using namespace std;

struct line {
    pair<int, int> rng;
    int pos;
    bool xs;

    line(pair<int, int> rng, int pos, bool xs) : rng(rng), pos(pos), xs(xs) {};
};

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

    if (n == 1 || m == 1) {
        cout << "INF" << endl;
        return;
    }

    vector<int> xs, ys;
    vector<line> lines;
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        xs.push_back(a);
        xs.push_back(b);
        ys.push_back(c);
        lines.emplace_back(make_pair(a, b), c, true);
    }

    for (int i = 0; i < m; i++) {
        int d, e, f;
        cin >> d >> e >> f;
        xs.push_back(d);
        ys.push_back(e);
        ys.push_back(f);
        lines.emplace_back(make_pair(e, f), d, false);
    }

    xs.push_back(2e+9);
    xs.push_back(0);
    xs.push_back(-2e+9);
    ys.push_back(2e+9);
    ys.push_back(0);
    ys.push_back(-2e+9);

    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());

    vector<vector<int>> hng(xs.size(), vector<int>(ys.size()));
    auto wng = hng;

    for (auto&& line : lines) {
        if (line.xs) {
            int ix1 = lower_bound(xs.begin(), xs.end(), line.rng.first) - xs.begin();
            int ix2 = lower_bound(xs.begin(), xs.end(), line.rng.second) - xs.begin();
            int iy = lower_bound(ys.begin(), ys.end(), line.pos) - ys.begin();
            hng[ix1][iy]++;
            hng[ix2][iy]--;
        }
        if (!line.xs) {
            int iy1 = lower_bound(ys.begin(), ys.end(), line.rng.first) - ys.begin();
            int iy2 = lower_bound(ys.begin(), ys.end(), line.rng.second) - ys.begin();
            int ix = lower_bound(xs.begin(), xs.end(), line.pos) - xs.begin();
            wng[ix][iy1]++;
            wng[ix][iy2]--;
        }
    }

    for (size_t i = 0; i < xs.size(); i++) {
        for (size_t j = 0; j < ys.size(); j++) {
            if (i < (xs.size() - 1))
                hng[i + 1][j] += hng[i][j];
            if (j < (ys.size() - 1))
                wng[i][j + 1] += wng[i][j];
        }
    }

    queue<pair<int, int>> search;
    pair<int, int> zero = { lower_bound(xs.begin(), xs.end(), 0) - xs.begin(),
                                 lower_bound(ys.begin(), ys.end(), 0) - ys.begin() };
    search.push(zero);

    vector<vector<int>> flag(xs.size() - 1, vector<int>(ys.size() - 1, 0));
    flag[zero.first][zero.second] = 1;

    long long area = 0;
    while (!search.empty()) {
        auto searching = search.front();
        if (searching.first < 1 || searching.second < 1 || searching.first >= (xs.size() - 2) || searching.second >= (ys.size() - 2)) {
            cout << "INF\n";
            return;
        }
        area += 1LL * (xs[searching.first + 1] - xs[searching.first]) * (ys[searching.second + 1] - ys[searching.second]);
        search.pop();
        if (!wng[searching.first][searching.second] && !flag[searching.first - 1][searching.second]) {
            search.push({ searching.first - 1, searching.second });
            flag[searching.first - 1][searching.second] = true;
        }
        if (!hng[searching.first][searching.second] && !flag[searching.first][searching.second - 1]) {
            search.push({ searching.first, searching.second - 1 });
            flag[searching.first][searching.second - 1] = true;
        }
        if (searching.first < (xs.size() - 2) && !wng[searching.first + 1][searching.second] && !flag[searching.first + 1][searching.second]) {
            search.push({ searching.first + 1, searching.second });
            flag[searching.first + 1][searching.second] = true;
        }
        if (searching.second < (ys.size() - 2) && !hng[searching.first][searching.second + 1] && !flag[searching.first][searching.second + 1]) {
            search.push({ searching.first, searching.second + 1 });
            flag[searching.first][searching.second + 1] = true;
        }
    }
    cout << area << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 109316