#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    V<ll> a(n), b(n), c(n), d(m), e(m), f(m), xs, ys;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        ys.eb(a[i]);
        ys.eb(b[i]);
        xs.eb(c[i]);
    }
    for (int i = 0; i < m; i++) {
        cin >> d[i] >> e[i] >> f[i];
        ys.eb(d[i]);
        xs.eb(e[i]);
        xs.eb(f[i]);
    }
    ys.eb(-INF);
    ys.eb(INF);
    xs.eb(-INF);
    xs.eb(INF);
    xs.eb(0);
    ys.eb(0);
    zip(ys);
    zip(xs);
    int yn = ys.size(), xn = xs.size();
    V<V<V<int>>> ok(yn, V<V<int>>(xn, V<int>(4, 1)));
    for (int i = 0; i < n; i++) {
        a[i] = lower_bound(all(ys), a[i]) - ys.begin();
        b[i] = lower_bound(all(ys), b[i]) - ys.begin();
        c[i] = lower_bound(all(xs), c[i]) - xs.begin();
        for (int j = a[i]; j < b[i]; j++) {
            ok[j][c[i] - 1][0] = 0;
            ok[j][c[i]][2] = 0;
        }
    }
    for (int i = 0; i < m; i++) {
        d[i] = lower_bound(all(ys), d[i]) - ys.begin();
        e[i] = lower_bound(all(xs), e[i]) - xs.begin();
        f[i] = lower_bound(all(xs), f[i]) - xs.begin();
        for (int j = e[i]; j < f[i]; j++) {
            ok[d[i]][j][1] = 0;
            ok[d[i] - 1][j][3] = 0;
        }
    }
    int sx = lower_bound(all(xs), 0) - xs.begin();
    int sy = lower_bound(all(ys), 0) - ys.begin();
    queue<P> q;
    q.emplace(sy, sx);
    V<V<int>> vis(yn, V<int>(xn));
    vis[sy][sx] = 1;
    while (!q.empty()) {
        int y = q.front().fi, x = q.front().se;
        q.pop();
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i], nx = x + dx[i];
            if (!ok[y][x][i] || ny < 0 || nx < 0 || ny >= yn || nx >= xn || vis[ny][nx]) continue;
            vis[ny][nx] = 1;
            q.emplace(ny, nx);
        }
    }
    ll res = 0;
    for (int i = 0; i < yn; i++) {
        for (int j = 0; j < xn; j++) {
            if (!vis[i][j]) continue;
            if (i == 0 || j == 0 || i == yn - 1 || j == xn - 1) {
                cout << 'I' << 'N' << 'F' << newl;
                return 0;
            }
            res += (ys[i + 1] - ys[i]) * (xs[j + 1] - xs[j]);
        }
    }
    cout << res << newl;
}

Measured memory_bytes: 531972