#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sign(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

using ll = long long;
int N, M;
ll A[1100], B[1100], C[1100];
ll D[1100], E[1100], F[1100];
bool wall[6600][6600];
vector<ll> py, px;
map<ll, int> zaty, zatx;

/*
void dfs(int y, int x) {
    wall[y][x] = 1;
    dump(y),dump(x);
    rep(i, 4) {
        int ny = y + DY[i], nx = x + DX[i];
        if (ny < 0 || nx < 0 || ny >= 6600 || nx >= 6600 || wall[ny][nx]) { continue; }
        dfs(ny, nx);
    }
}
*/
void dfs(int y, int x) {
    stack<pint> stk;
    stk.emplace(y, x);
    while (!stk.empty()) {
        int cy = stk.top().first, cx = stk.top().second;
        wall[cy][cx] = 1;
        stk.pop();
        rep(i, 4) {
            int ny = cy + DY[i], nx = cx + DX[i];
            if (ny < 0 || nx < 0 || ny >= 6600 || nx >= 6600 || wall[ny][nx]) { continue; }
            stk.emplace(ny, nx);
        }
    }
}
signed main() {
    cin >> N >> M;
    py.emplace_back(0), px.emplace_back(0);
    py.emplace_back(INT_MIN), px.emplace_back(INT_MIN);
    rep(i, N) {
        cin >> A[i] >> B[i] >> C[i];
        py.emplace_back(A[i]), py.emplace_back(B[i]), px.emplace_back(C[i]);
    }
    rep(i, M) {
        cin >> D[i] >> E[i] >> F[i];
        py.emplace_back(D[i]), px.emplace_back(E[i]), px.emplace_back(F[i]);
    }
    sort(all(py)), uniq(py);
    sort(all(px)), uniq(px);
    rep(i, py.size()) { zaty[py[i]] = i; }
    rep(i, px.size()) { zatx[px[i]] = i; }
    rep(i, N) {
        int y0 = zaty[A[i]] * 2, y1 = zaty[B[i]] * 2, x = zatx[C[i]] * 2;
        for (int j = y0; j <= y1; j++) { wall[j][x] = 1; }
    }
    rep(i, M) {
        int y = zaty[D[i]] * 2, x0 = zatx[E[i]] * 2, x1 = zatx[F[i]] * 2;
        for (int j = x0; j <= x1; j++) { wall[y][j] = 1; }
    }
    dfs(zaty[0] * 2, zatx[0] * 2);

    if (wall[0][0] || wall[0][6600 - 1] || wall[6600 - 1][0] || wall[6600 - 1][6600 - 1]) { fin("INF"); }
    long long ans = 0;
    rep(i, 6600) {
        rep(j, 6600) {
            if ((i & 1) && (j & 1) && wall[i][j]) {
                ans += (py[i / 2 + 1] - py[i / 2]) * (px[j / 2 + 1] - px[j / 2]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 401928