#include <bits/stdc++.h>

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define dprintf(...) printf(__VA_ARGS__)
#else
#define PRINT(x)
#define dprintf(...)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using T = tuple<int, int, int>;

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}


const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

enum {
    UP,
    RIGHT,
    DOWN,
    LEFT,
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N), C(N), D(M), E(M), F(M);
    REP(i, N) cin >> A[i] >> B[i] >> C[i];
    REP(i, M) cin >> D[i] >> E[i] >> F[i];

    vector<int> X, Y;
    REP(i, N) {
        X.push_back(A[i]);
        X.push_back(B[i]);
        Y.push_back(C[i]);
    }
    REP(i, M) {
        X.push_back(D[i]);
        Y.push_back(E[i]);
        Y.push_back(F[i]);
    }
    sort(all(X));
    sort(all(Y));
    X.erase(unique(all(X)), X.end());
    Y.erase(unique(all(Y)), Y.end());
    int H = X.size();
    int W = Y.size();
        
    int si = lower_bound(all(X), 0) - X.begin();
    int sj = lower_bound(all(Y), 0) - Y.begin();
    if (si == 0 || si == H || sj == 0 || sj == W) {
        cout << "INF" << endl;
        return 0;
    }

    vector<vector<vector<bool>>> wall(H + 1, vector<vector<bool>>(W + 1, vector<bool>(4)));
    REP(j, N) {
        int p_A = lower_bound(all(X), A[j]) - X.begin();
        int p_B = lower_bound(all(X), B[j]) - X.begin();
        int p_C = lower_bound(all(Y), C[j]) - Y.begin();
        int j0 = p_C;
        int j1 = p_C + 1;
        FOR(i, p_A + 1, p_B + 1) {
            wall[i][j0][RIGHT] = true;
            wall[i][j1][LEFT] = true;
        }
    }
    REP(i, M) {
        int p_D = lower_bound(all(X), D[i]) - X.begin();
        int p_E = lower_bound(all(Y), E[i]) - Y.begin();
        int p_F = lower_bound(all(Y), F[i]) - Y.begin();
        int i0 = p_D;
        int i1 = p_D + 1;
        FOR(j, p_E + 1, p_F + 1) {
            wall[i0][j][UP] = true;
            wall[i1][j][DOWN] = true;
        }
    }

    ll result = 0;
    vector<vector<bool>> used(H + 1, vector<bool>(W + 1));
    queue<pii> q;
    used[si][sj] = true;
    result += ll(X[si] - X[si - 1]) * (Y[sj] - Y[sj - 1]);
    q.emplace(si, sj);
    function<void(void)> print_map = [&]() {
        REP(i, H) {
            REP(j, W + 1) {
                if (used[i][j]) {
                    dprintf("*");
                } else {
                    dprintf(" ");
                }
                if (wall[i][j][RIGHT]) {
                    dprintf("|");
                } else {
                    dprintf(" ");
                }
            }
            dprintf("\n");
            REP(j, W + 1) {
                if (wall[i][j][UP]) {
                    dprintf("- ");
                } else {
                    dprintf("  ");
                }
            }
            dprintf("\n");
        }
    };
    print_map();
    while (!q.empty()) {
        auto [i, j] = q.front();
        q.pop();
        PRINT(pii(i, j));
        REP(k, 4) {
            if (!wall[i][j][k]) {
                int ii = i + dx[k];
                int jj = j + dy[k];
                if (ii == 0 || ii == H || jj == 0 || jj == W) {
                    cout << "INF" << endl;
                    return 0;
                }
                if (!used[ii][jj]) {
                    //vector<string> dirs = {"UP", "RIGHT", "DOWN", "LEFT"};
                    //dprintf("go %s\n", dirs[k].c_str());
                    used[ii][jj] = true;
                    result += ll(X[ii] - X[ii - 1]) * (Y[jj] - Y[jj - 1]);
                    q.emplace(ii, jj);
                    print_map();
                }
            }
        }
    }

    cout << result << endl;

    print_map();

    return 0;
}


Measured memory_bytes: 638248