// 解説動画そのまんま、、
// いつか復習したい
#include <bits/stdc++.h>
using namespace std;

struct L {
    int a, b, c;
    L(int _a = 0, int _b = 0, int _c = 0) : a(_a), b(_b), c(_c) {}
};

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

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mpX, mpY;
    mpX[0] = 0;
    mpY[0] = 0;

    vector<L> lh, lv;
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        mpX[a] = 0;
        mpX[b] = 0;
        mpY[c] = 0;
        lh.emplace_back(a, b, c);
    }
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> c >> a >> b;
        mpY[a] = 0;
        mpY[b] = 0;
        mpX[c] = 0;
        lv.emplace_back(a, b, c);
    }

    vector<int> xs, ys;
    for (auto &p : mpX) {
        p.second = xs.size();
        xs.push_back(p.first);
    }
    for (auto &p : mpY) {
        p.second = ys.size();
        ys.push_back(p.first);
    }

    int h = xs.size() * 2;
    int w = ys.size() * 2;

    vector<vector<int>> d(h, vector<int>(w));

    for (int i = 0; i < n; ++i) {
        int a = mpX[lh[i].a] * 2;
        int b = mpX[lh[i].b] * 2;
        int c = mpY[lh[i].c] * 2;
        for (int x = a; x <= b; ++x) d[x][c] = -1;
    }

    for (int i = 0; i < m; ++i) {
        int a = mpY[lv[i].a] * 2;
        int b = mpY[lv[i].b] * 2;
        int c = mpX[lv[i].c] * 2;
        for (int y = a; y <= b; ++y) d[c][y] = -1;
    }

    queue<pair<int, int>> q;
    int sx = mpX[0] * 2, sy = mpY[0] * 2;
    d[sx][sy] = 1;
    q.emplace(sx, sy);
    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int v = 0; v < 4; ++v) {
            int nx = x + dx[v], ny = y + dy[v];
            if (nx < 0 || nx >= h) continue;
            if (ny < 0 || ny >= w) continue;
            if (d[nx][ny] != 0) continue;
            d[nx][ny] = 1;
            q.emplace(nx, ny);
        }
    }

    long long ans = 0;
    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            if (d[x][y] != 1) continue;
            if (x == 0 || x == h - 1 || y == 0 || y == w - 1) {
                cout << "INF" << endl;
                return 0;
            }
            if (x % 2 == 0 || y % 2 == 0) continue;
            // x/2 + 1が配列の参照外に当たりそうだけど、x == h-1の条件は上で処理してあるから大丈夫
            long long ex = xs[x / 2 + 1] - xs[x / 2];
            long long ey = ys[y / 2 + 1] - ys[y / 2];
            ans += ex * ey;
        }
    }
    cout << ans << endl;
    return 0;
}