#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<int> A(N), B(N), C(N);
    for (int i=0; i<N; i++)
        cin>>A[i]>>B[i]>>C[i];
    vector<int> D(M), E(M), F(M);
    for (int i=0;i <M; i++)
        cin>>D[i]>>E[i]>>F[i];

    map<int, int> MX;
    MX[0] = 0;
    for (int i=0; i<N; i++)
    {
        MX[A[i]] = 0;
        MX[B[i]] = 0;
    }
    for (int i=0; i<M; i++)
        MX[D[i]] = 0;
    int c = 0;
    vector<int> VX;
    for (auto &m: MX)
    {
        VX.push_back(m.first);
        m.second = c++;
    }

    map<int, int> MY;
    MY[0] = 0;
    for (int i=0; i<N; i++)
        MY[C[i]] = 0;
    for (int i=0; i<M; i++)
    {
        MY[E[i]] = 0;
        MY[F[i]] = 0;
    }
    c = 0;
    vector<int> VY;
    for (auto &m: MY)
    {
        VY.push_back(m.first);
        m.second = c++;
    }

    int w = (int)MX.size();
    int h = (int)MY.size();

    vector<string> T(2*h, string(2*w, '.'));
    for (int i=0; i<N; i++)
    {
        int y = MY[C[i]]*2;
        for (int x=MX[A[i]]*2; x<=MX[B[i]]*2; x++)
            T[y][x] = '#';
    }
    for (int i=0; i<M; i++)
    {
        int x = MX[D[i]]*2;
        for (int y=MY[E[i]]*2; y<=MY[F[i]]*2; y++)
            T[y][x] = '#';
    }

    vector<pair<int, int>> Q;
    T[MY[0]*2][MX[0]*2] = '*';
    Q.push_back(make_pair(MX[0]*2, MY[0]*2));
    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};
    for (int q=0; q<(int)Q.size(); q++)
    {
        int x = Q[q].first;
        int y = Q[q].second;
        for (int d=0; d<4; d++)
        {
            int tx = x + dx[d];
            int ty = y + dy[d];
            if (0<=tx && tx<2*w && 0<=ty && ty<2*h &&
                T[ty][tx]=='.')
            {
                T[ty][tx] = '*';
                Q.push_back(make_pair(tx, ty));
            }
        }
    }

    //for (string t: T)
    //    cout<<t<<endl;

    long long ans = 0;
    for (int y=0; y<2*h; y++)
        for (int x=0; x<2*w; x++)
            if (T[y][x]=='*')
            {
                if (x==0 || y==0 || x==2*w-1 || y==2*h-1)
                {
                    cout<<"INF"<<endl;
                    return 0;
                }

                ans += (long long)(VX[(x+1)/2]-VX[x/2])*(VY[(y+1)/2]-VY[y/2]);
            }
    cout<<ans<<endl;
}
