#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e9;
//const ll mod = 1000000007;
ll N, M;
ll A[1005], B[1005], C[1005];
ll D[1005], E[1005], F[1005];
vector<ll> Hcmp, Wcmp;
vector<vector<bool>> Right, Up;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};


int main() {
    cin >> N >> M;
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i] >> C[i];
        Hcmp.push_back(A[i]);
        Hcmp.push_back(B[i]);
        Wcmp.push_back(C[i]-1);
        Wcmp.push_back(C[i]);
        Wcmp.push_back(C[i]+1);
    }
    for(int i = 0; i < M; i++) {
        cin >> D[i] >> E[i] >> F[i];
        Hcmp.push_back(D[i]-1);
        Hcmp.push_back(D[i]);
        Hcmp.push_back(D[i]+1);
        Wcmp.push_back(E[i]);
        Wcmp.push_back(F[i]);
    }
    Hcmp.push_back(-INF - 1);
    Wcmp.push_back(-INF - 1);
    Hcmp.push_back(0);
    Wcmp.push_back(0);
    sort(Hcmp.begin(), Hcmp.end());
    sort(Wcmp.begin(), Wcmp.end());
    Hcmp.erase(unique(Hcmp.begin(), Hcmp.end()), Hcmp.end());
    Wcmp.erase(unique(Wcmp.begin(), Wcmp.end()), Wcmp.end());
    //for(auto h : Hcmp) cerr << h << " ";
    //cerr << endl;
    //for(auto w : Wcmp) cerr << w << " ";
    //cerr << endl;
    ll H = Hcmp.size();
    ll W = Wcmp.size();
    //cerr << "H: " << H << endl;
    //cerr << "W: " << W << endl;
    Right.resize(H, vector<bool>(W, false));
    Up.resize(H, vector<bool>(W, false));
    for(int i = 0; i < N; i++) {
        auto itr = lower_bound(Hcmp.begin(), Hcmp.end(), A[i]);
        A[i] = itr - Hcmp.begin();
        itr = lower_bound(Hcmp.begin(), Hcmp.end(), B[i]);
        B[i] = itr - Hcmp.begin();
        itr = lower_bound(Wcmp.begin(), Wcmp.end(), C[i]);
        C[i] = itr - Wcmp.begin();
    }
    for(int i = 0; i < M; i++) {
        auto itr = lower_bound(Hcmp.begin(), Hcmp.end(), D[i]);
        D[i] = itr - Hcmp.begin();
        itr = lower_bound(Wcmp.begin(), Wcmp.end(), E[i]);
        E[i] = itr - Wcmp.begin();
        itr = lower_bound(Wcmp.begin(), Wcmp.end(), F[i]);
        F[i] = itr - Wcmp.begin();
    }
    UnionFind uni(H * W);
    ll sumsize = 0;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            ll val = 0;
            if(h != H - 1 and w != W - 1) {
                val = (Hcmp[h+1] - Hcmp[h]) * (Wcmp[w+1] - Wcmp[w]);
            }
            uni.Size[h*W+w] = val;
            sumsize += val;
        }
    }
    for(int i = 0; i < N; i++) {
        for(int j = A[i]; j < B[i]; j++) {
            Right[j][C[i]] = true;
            //cerr << "right: " << j << " " << C[i] << endl;
        }
    }
    for(int i = 0; i < M; i++) {
        for(int j = E[i]; j < F[i]; j++) {
            Up[D[i]][j] = true;
            //cerr << "up: " << D[i] << " " << j << endl;
        }
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(i != 0 and !Up[i][j]) {
                uni.merge((i-1)*W+j, i*W+j);
                //cerr << "upmerge: " << i << " " << j << endl;
            }
            if(j != 0 and !Right[i][j]) {
                uni.merge(i*W+j-1, i*W+j);
            }
        }
    }
    /*
    cerr << "-------------------" << endl;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(Up[i][j]) cerr << i << " " << j << endl;
        }
    }
    cerr << "-------------------" << endl;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(Right[i][j]) cerr << i << " " << j << endl;
        }
    }
    cerr << "-------------------" << endl;
    */
    for(int i = 0; i < H * W; i++) {
        if(uni.root(i) != i) continue;
        ll h = i / W;
        ll w = i % W;
        //cerr << "(" << h << ", " << w << ") (" << Hcmp[h] << ", " << Wcmp[w] << ")" << uni.size(i) << endl;
    }
    for(int i = 0; i < H * W; i++) {
        ll h = i / W;
        ll w = i % W;
        //cerr << h << " " << w << " ";
        h = uni.root(i) / W;
        w = uni.root(i) % W;
        //cerr << h << " " << w << endl;
    }
    int zeroh = 0;
    while(Hcmp[zeroh] != 0) zeroh++;
    int zerow = 0;
    while(Wcmp[zerow] != 0) zerow++;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            bool ok = false;
            if(h == 0) ok = true;
            if(h == H - 1) ok = true;
            if(w == 0) ok = true;
            if(w == W - 1) ok = true;
            if(!ok) continue;
            if(uni.issame(h*W+w, zeroh*W+zerow)) {
                cout << "INF" << endl;
                return 0;
            }
        }
    }
    ll ans = uni.size(zeroh * W + zerow);
    cout << ans << endl;
    //cerr << "sumsize: " << sumsize << endl;
    return 0;
}


Measured memory_bytes: 401092