#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>
long double pi = boost::math::constants::pi<long double>();
using namespace std;
typedef long long ll;
int N, M;
int A[1010], B[1010], C[1010], D[1010], E[1010], F[1010];
vector<int> x, y;
bool mpx[6020][6020], mpy[6020][6020];
bool mp[6020][6020];
queue<pair<int, int>> que;
int main() {
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        cin >> A[i] >> B[i] >> C[i];
        x.push_back(A[i]);
        x.push_back(B[i]);
        y.push_back(C[i]);
    }
    for (int i = 1; i <= M; i++) {
        cin >> D[i] >> E[i] >> F[i];
        x.push_back(D[i]);
        y.push_back(E[i]);
        y.push_back(F[i]);
    }
    x.push_back(0);
    y.push_back(0);
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    for (int i = 1; i <= N; i++) {
        A[i] = lower_bound(x.begin(), x.end(), A[i])-x.begin();
        B[i] = lower_bound(x.begin(), x.end(), B[i])-x.begin();
        C[i] = lower_bound(y.begin(), y.end(), C[i])-y.begin();
        for (int a = A[i]*2+1; a < B[i]*2; a++) {
            mpy[a][C[i]*2] = 1;
        }
    }
    for (int i = 1; i <= M; i++) {
        D[i] = lower_bound(x.begin(), x.end(), D[i])-x.begin();
        E[i] = lower_bound(y.begin(), y.end(), E[i])-y.begin();
        F[i] = lower_bound(y.begin(), y.end(), F[i])-y.begin();
        for (int a = E[i]*2+1; a < F[i]*2; a++) {
            mpx[D[i]*2][a] = 1;
        }
    }
    int s = lower_bound(x.begin(), x.end(), 0)-x.begin();
    int t = lower_bound(y.begin(), y.end(), 0)-y.begin();
    mp[s*2][t*2] = 1;
    que.push(make_pair(s*2,t*2));
    while (que.size()) {
        int x = que.front().first, y = que.front().second;
        que.pop();
        int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
        for (int i = 0; i < 4; i++) {
            int nx = dx[i]+x, ny = dy[i]+y;
            if (nx >= 0 && nx < 6020 && ny >= 0 && ny < 6020) {
                if (!mpx[nx][ny] && !mpy[nx][ny] && mp[nx][ny] != 1) {
                    mp[nx][ny] = 1;
                    que.push(make_pair(nx, ny));
                }
            }
            else {
                puts("INF");
                return 0;
            }
        }
    }
    ll ans = 0;
    for (int i = 1, xl = x.size(); (i+1)/2 < xl; i+=2) {
        for (int j = 1, yl = y.size(); (j+1)/2 < yl; j+=2) {
            if (mp[i][j]) {
                ans += ((ll)x[(i+1)/2]-x[(i-1)/2])*((ll)y[(j+1)/2]-y[(j-1)/2]);
            }
        }
    }
    cout << ans << endl;
    /*
    for (int j = 29; j >= 0; j--) {
        for (int i = 0; i < 30; i++) {
            if (mp[i][j]) {
                cout << '@';
            }
            else if (mpx[i][j] || mpy[i][j]) {
                cout << '#';
            }
            else {
                cout << '.';
            }
        }
        cout << endl;
    }
    //*/
}