#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    vector<pair<unsigned long, pair<unsigned long, unsigned long>>> vt(N), hr(M);
    vector<unsigned long> xs, ys;
    constexpr unsigned long ofs = 1100000000;
    for(auto&& [i, j] : vt){
        long a, b, c;
        cin >> a >> b >> c;
        i = (c + ofs) * 2;
        ys.push_back(i);
        j = {(a + ofs) * 2, (b + ofs) * 2};
        xs.push_back(j.first);
        xs.push_back(j.second);
    }
    for(auto&& [i, j] : hr){
        long d, e, f;
        cin >> d >> e >> f;
        i = (d + ofs) * 2;
        xs.push_back(i);
        j = {(e + ofs) * 2, (f + ofs) * 2};
        ys.push_back(j.first);
        ys.push_back(j.second);
    }
    sort(vt.begin(), vt.end());
    sort(hr.begin(), hr.end());
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    const auto vt_locked = [&vt](unsigned long x, unsigned long y) -> bool {
        auto t = lower_bound(vt.begin(), vt.end(), pair<unsigned long, pair<unsigned long, unsigned long>>{y, pair<unsigned long, unsigned long>{0, 0}});
        return t[0].second.first <= x && x <= t[0].second.second;
    };
    const auto hr_locked = [&hr](unsigned long x, unsigned long y) -> bool {
        auto t = lower_bound(hr.begin(), hr.end(), pair<unsigned long, pair<unsigned long, unsigned long>>{x, pair<unsigned long, unsigned long>{0, 0}});
        return t[0].second.first <= y && y <= t[0].second.second;
    };
    deque visited(xs.size() + 1, deque(ys.size() + 1, false));
    queue<pair<unsigned long, unsigned long>> q;
    q.emplace(lower_bound(xs.begin(), xs.end(), 2 * ofs + 1) - xs.begin(), lower_bound(ys.begin(), ys.end(), 2 * ofs - 1) - ys.begin());
    unsigned long ans{0};
    while(!q.empty()){
        auto [x, y] = q.front();
        q.pop();
        if(x == 0 || y == 0 || x == xs.size() || y == ys.size())return 0 & puts("INF");
        if(visited[x][y])continue;
        visited[x][y] = true;
        ans += (xs[x] - xs[x - 1]) * (ys[y] - ys[y - 1]) / 4;
        if(!hr_locked(xs[x], (ys[y] + ys[y - 1]) / 2) && !visited[x + 1][y])q.emplace(x + 1, y);
        if(!hr_locked(xs[x - 1], (ys[y] + ys[y - 1]) / 2) && !visited[x - 1][y])q.emplace(x - 1, y);
        if(!vt_locked((xs[x] + xs[x - 1]) / 2, ys[y]) && !visited[x][y + 1])q.emplace(x, y + 1);
        if(!vt_locked((xs[x] + xs[x - 1]) / 2, ys[y - 1]) && !visited[x][y - 1])q.emplace(x, y - 1);
    }
    cout << ans << endl;
    return 0;
}