// 問題の URL を書いておく
// 

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <queue>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

void DumpGrid(vector<vector<int>>& grid)
{
#if 0
    for(auto& v : grid)
    {
        for(auto& h : v)
        {
            cout << (char)('.' + h);
        }
        cout << endl;
    }
#endif
}

int main(int, const char**)
{
    int n, m;
    cin >> n >> m;
    struct Point
    {
        int64_t x;
        int64_t y;
    };

    struct Line
    {
        int64_t a;
        int64_t b;
        int64_t c;
    };

    set<int64_t> xs, ys;
    vector<Line> vl(n), hl(m);
    for(int i = 0; i < n; ++i)
    {
        int64_t a, b, c;
        cin >> a >> b >> c;
        xs.insert(c);
        ys.insert(a);
        ys.insert(b);
        vl[i] = {a, b, c};
    }
    for(int i = 0; i < m; ++i)
    {
        int64_t d, e, f;
        cin >> d >> e >> f;
        xs.insert(e);
        xs.insert(f);
        ys.insert(d);
        hl[i] = {d, e, f};
    }

    xs.insert(0);
    ys.insert(0);
    map<int64_t, int> xmap;
    map<int, int64_t> rxmap;
    {
        auto itr = xs.begin();
        for(int i = 0; i < xs.size(); ++i)
        {
            xmap[*itr] = i;
            rxmap[i] = *itr;
            ++itr;
        }
    }
#if 0
    for(auto x : xs)
    {
        cout << x << "," << xmap[x] << endl;
    }
#endif

    map<int64_t, int> ymap;
    map<int, int64_t> rymap;
    {
        auto itr = ys.begin();
        for(int i = 0; i < ys.size(); ++i)
        {
            ymap[*itr] = i;
            rymap[i] = *itr;
            ++itr;
        }
    }

    vector<vector<int>> grid(ys.size() * 2, vector<int>(xs.size() * 2, 0));
    for(auto& l : vl)
    {
        auto x = xmap[l.c];
        auto y0 = ymap[l.a];
        auto y1 = ymap[l.b];
        for(int i = y0; i < y1; ++i)
        {
            grid[i * 2][x * 2] = 1;
            grid[i * 2 + 1][x * 2] = 1;
        }
        grid[y1 * 2][x * 2] = 1;
    }

    for(auto& l : hl)
    {
        auto y = ymap[l.a];
        auto x0 = xmap[l.b];
        auto x1 = xmap[l.c];
        for(int i = x0; i < x1; ++i)
        {
            grid[y * 2][i * 2] = 1;
            grid[y * 2][i * 2 + 1] = 1;
        }
        grid[y * 2][x1 * 2] = 1;
    }

//    grid[ymap[0] * 2][xmap[0] * 2] = 2;

    DumpGrid(grid);

    queue<Point> q;
    q.push({xmap[0] * 2, ymap[0] * 2});
    bool inf = false;
    int64_t area = 0;
    while(!q.empty())
    {
        auto tp = q.front();
        q.pop();
        
        auto x = tp.x;
        auto y = tp.y;
        if(grid[y][x] != 0)
        {
            continue;
        }

        if(x == 0 || y == 0 || x == xs.size() * 2 - 1 || y == ys.size() * 2 - 1)
        {
            inf = true;
            break;
        }

        if(x % 2 == 1 && y % 2 == 1)
        {
            auto tx = x / 2;
            auto ty = y / 2;

            auto w = (rxmap[tx + 1] - rxmap[tx]);
            auto h = (rymap[ty + 1] - rymap[ty]);
            area += w * h;
        }

        grid[y][x] = 2;
        q.push({x + 1, y});
        q.push({x - 1, y});
        q.push({x, y + 1});
        q.push({x, y - 1});
        DumpGrid(grid);
    }

    if(inf)
    {
        cout << "INF" << endl;
    }
    else
    {
        cout << area << endl;
    }

    return 0;
}


Measured memory_bytes: 145244