#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
// #define DEBUG
#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

template <typename T> struct Compress {
    vector<T> v;
    Compress() {}
    Compress(vector<T> vv) : v(vv) {
        sort(ALL(v));
        v.erase(unique(ALL(v)), end(v));
    }
    void build(vector<T> vv) {
        v = vv;
        sort(ALL(v));
        v.erase(unique(ALL(v)), end(v));
    }
    int get(T x) { return (int)(lower_bound(ALL(v), x) - v.begin()); }
    T &operator[](int i) { return v[i]; }
    size_t size() { return v.size(); }
};

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

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

    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(par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) { return -par[root(x)]; }
};

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);
    vector<int> X = {-INF, INF};
    vector<int> Y = {-INF, INF};
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i] >> C[i];
        X.emplace_back(A[i]);
        X.emplace_back(B[i]);
        Y.emplace_back(C[i]);
    }
    for(int i = 0; i < M; i++) {
        cin >> D[i] >> E[i] >> F[i];
        X.emplace_back(D[i]);
        Y.emplace_back(E[i]);
        Y.emplace_back(F[i]);
    }
    Compress<int> comp_x(X), comp_y(Y);
    int nx = (int)comp_x.size();
    int ny = (int)comp_y.size();
    vector exx(nx, vector(ny, false));
    vector exy(nx, vector(ny, false));
    // 縦線
    for(int i = 0; i < N; i++) {
        int a = comp_x.get(A[i]);
        int b = comp_x.get(B[i]);
        int c = comp_y.get(C[i]);
        for(int j = a; j < b; j++) {
            exx[j][c] = true;
        }
    }
    // 横線
    for(int i = 0; i < M; i++) {
        int d = comp_x.get(D[i]);
        int e = comp_y.get(E[i]);
        int f = comp_y.get(F[i]);
        for(int j = e; j < f; j++) {
            exy[d][j] = true;
        }
    }
    UnionFind uf(nx * ny);
    for(int i = 0; i < nx - 1; i++) {
        for(int j = 0; j < ny - 1; j++) {
            if(!exx[i][j + 1]) {
                if(j + 1 >= ny - 1) {
                    continue;
                }
                uf.merge(i * (nx - 1) + j, i * (nx - 1) + j + 1);
                debug(i, j, "-", i, j + 1);
            }
            if(!exy[i + 1][j]) {
                if(i + 1 >= nx - 1) {
                    continue;
                }
                debug(i, j, "-", i + 1, j);
                uf.merge((i + 1) * (nx - 1) + j, i * (nx - 1) + j);
            }
        }
    }
    int ushi = (nx - 1) * (comp_x.get(0) - 1) + comp_y.get(0) - 1;
    debug(ushi / (nx - 1), ushi % (nx - 1));
    debug(nx, ny);
    ll ans = 0;
    for(int i = 0; i < nx - 1; i++) {
        for(int j = 0; j < ny - 1; j++) {
            int now = i * (nx - 1) + j;
            if(i == 0 || j == 0 || i == nx - 2 || j == ny - 2) {
                if(uf.issame(ushi, now)) {
                    debug(i, j);
                    cout << "INF\n";
                    return 0;
                }
            }
            if(uf.issame(ushi, now)) {
                debug(i, j);
                ll x = comp_x[i + 1] - comp_x[i];
                ll y = comp_y[j + 1] - comp_y[j];
                ans += x * y;
            }
        }
    }
    cout << ans << "\n";
}