#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

template <typename T>
struct Compress {
    vector<T> xs;

    Compress() = default;

    Compress(const vector<T>& vs) {
        add(vs);
    }

    Compress(const initializer_list<vector<T>>& vs) {
        for (auto& p : vs)
            add(p);
    }

    void add(const vector<T>& vs) {
        copy(begin(vs), end(vs), back_inserter(xs));
    }

    void add(const T& x) {
        xs.emplace_back(x);
    }

    void build() {
        sort(begin(xs), end(xs));
        xs.erase(unique(begin(xs), end(xs)), end(xs));
    }

    vector<int> get(const vector<T>& vs) const {
        vector<int> ret;
        transform(begin(vs), end(vs), back_inserter(ret), [&](const T& x) {
            return lower_bound(begin(xs), end(xs), x) - begin(xs);
        });
        return ret;
    }

    int get(const T& x) const {
        return lower_bound(begin(xs), end(xs), x) - begin(xs);
    }

    const T& operator[](int k) const {
        return xs[k];
    }
};

int N, M;
vector<int> A, B, C, D, E, F;

int can_go[4000][4000];
int wall_h[4000][4000];
int wall_v[4000][4000];

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

void solve() {
    Compress<int> com_x, com_y;
    com_x.add(1e10);
    com_y.add(1e10);
    com_x.add(-1e10);
    com_y.add(-1e10);
    com_x.add(1e10 + 1);
    com_y.add(1e10 + 1);
    com_x.add(-1e10 - 1);
    com_y.add(-1e10 - 1);
    com_x.add(A);
    com_x.add(B);
    com_y.add(C);
    com_x.add(D);
    com_y.add(E);
    com_y.add(F);
    com_x.add(0);
    com_y.add(0);
    com_x.build();
    com_y.build();

    FOR (N) {
        int l = com_x.get(A[i]) + 1, r = com_x.get(B[i]);
        int y = com_y.get(C[i]);
        for (int x = l; x <= r; x++) {
            wall_h[x][y] = 1;
        }
    }
    FOR (M) {
        int x = com_x.get(D[i]);
        int d = com_y.get(E[i]) + 1, u = com_y.get(F[i]);
        for (int y = d; y <= u; y++) {
            wall_v[x][y] = 1;
        }
    }

    queue<pair<int, int>> que;
    que.push({com_x.get(0) + 1, com_y.get(0) + 1});

    while (!que.empty()) {
        auto p = que.front();
        que.pop();

        int x = p.first;
        int y = p.second;
        if (abs(com_x[x]) >= 1e10 || abs(com_y[y]) > 1e10) {
            cout << "INF" << endl;
            return;
        }
        if (can_go[x][y])
            continue;
        can_go[x][y] = 1;

        FOR (4) {
            if (!wall_v[x][y]) {
                que.push({x + 1, y});
            }
            if (!wall_h[x][y])
                que.push({x, y + 1});
            if (!wall_v[x - 1][y])
                que.push({x - 1, y});
            if (!wall_h[x][y - 1])
                que.push({x, y - 1});
        }
    }

    int ans = 0;
    FOR (x, 1, 3100) {
        FOR (y, 1, 3100) {
            if (can_go[x][y]) {
                ans += (com_x[x] - com_x[x - 1]) * (com_y[y] - com_y[y - 1]);
            }
        }
    }

    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    A.resize(N);
    B.resize(N);
    C.resize(N);
    D.resize(M);
    E.resize(M);
    F.resize(M);

    FOR (N)
        cin >> A[i] >> B[i] >> C[i];
    FOR (M)
        cin >> D[i] >> E[i] >> F[i];

    solve();
    return 0;
}


Measured memory_bytes: 160220