#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct L {
    int a, b, c;
    L(int a, int b, int c): a(a), b(b), c(c) {}
};


int main(){
    int n, m;
    cin >> n >> m;
    vector<L> lh;
    vector<L> lv;
    map<int, int> mpx;
    map<int, int> mpy;
    mpx[0] = 0;
    mpy[0] = 0;

    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        lh.emplace_back(a, b, c);
        mpx[a] = 0;
        mpx[b] = 0;
        mpy[c] = 0;
    }
    rep(i, m) {
        int d, e, f;
        cin >> d >> e >> f;
        lv.emplace_back(e, f, d);
        mpx[d] = 0;
        mpy[e] = 0;
        mpy[f] = 0;
    }

    vector<int> xs;
    vector<int> ys;

    for (auto& m: mpx) {
        m.second = xs.size();
        xs.push_back(m.first);
    }
    for (auto& m: mpy) {
        m.second = ys.size();
        ys.push_back(m.first);
    }
    int nx = xs.size() * 2;
    int ny = ys.size() * 2;

    vector<vector<int>> g(nx, vector<int>(ny));
    rep(i, n) {
        int a = mpx[lh[i].a]*2;
        int b = mpx[lh[i].b]*2;
        int c = mpy[lh[i].c]*2;
        for (int x=a; x<=b; x++) g[x][c] = -1;
    }
    rep(i, m) {
        int a = mpy[lv[i].a]*2;
        int b = mpy[lv[i].b]*2;
        int c = mpx[lv[i].c]*2;
        for (int y=a; y<=b; y++) g[c][y] = -1;
    }

    queue<P> q;
    P start = P(mpx[0]*2, mpy[0]*2);
    g[start.first][start.second] = 1;
    q.push(start);
    //debug(nx);

    while (!q.empty()) {
        auto now = q.front();
        q.pop();
        int x = now.first;
        int y = now.second;
        rep(i, 4) {
            int ix = x + dx[i];
            int iy = y + dy[i];
            if (ix<0 || ix>=nx || iy<0 || iy>=ny) continue;
            if (g[ix][iy]!=0) continue;
            g[ix][iy] = 1;
            q.emplace(ix, iy);
        }
    }

    ll ans = 0;
    rep(i, nx) rep(j, ny) {
        if (g[i][j]!=1) continue;
        if (i==0 || i==nx-1 || j==0 || j==ny-1) {
            cout << "INF" << endl;
            return 0;
        }
        if (i%2==0 || j%2==0) continue;
        ll dx = xs[i/2+1] - xs[i/2];
        ll dy = ys[j/2+1] - ys[j/2];
        ans += dx*dy;
    }
    cout << ans << endl;
    return 0;
}
