#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>

struct Line{
    int a, b, c;
};

int main() {
    int n, m; std::cin >> n >> m;
    std::vector<Line> h(n), v(m);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i].b >> h[i].c >> h[i].a;
        if (h[i].b > h[i].c) std::swap(h[i].b, h[i].c);
        h[i].a *= 2; h[i].b *= 2; h[i].c *= 2;
    }
    for (int i = 0; i < m; i++) {
        std::cin >> v[i].a >> v[i].b >> v[i].c;
        if (v[i].b > v[i].c) std::swap(v[i].b, v[i].c);
        v[i].a *= 2; v[i].b *= 2; v[i].c *= 2;
    }
    std::map<int, int> lmp, rmp;
    for (int i = 0; i < n; i++) {
        for (int t = -1; t <= 1; t++) {
            lmp[h[i].b + t]; lmp[h[i].c + t];
            rmp[h[i].a + t];
        }
    }
    for (int i = 0; i < m; i++) {
        for (int t = -1; t <= 1; t++) {
            rmp[v[i].b + t]; rmp[v[i].c + t];
            lmp[v[i].a + t];
        }
    }
    for (int t = -1; t <= 1; t++) {
        lmp[t]; rmp[t];
    }
    int cntl = 0, cntr = 0;
    for (auto &p : lmp) p.second = cntl++;
    for (auto &p : rmp) p.second = cntr++;
    std::vector<std::vector<int>> tab(cntl, std::vector<int>(cntr));
    for (int i = 0; i < n; i++) {
        int u = rmp[h[i].a];
        for (int j = lmp[h[i].b]; j <= lmp[h[i].c]; j++) {
            tab[j][u] = -1;
        }
    }
    for (int i = 0; i < m; i++) {
        int u = lmp[v[i].a];
        for (int j = rmp[v[i].b]; j <= rmp[v[i].c]; j++) {
            tab[u][j] = -1;
        }
    }
    std::vector<int> d = { 1,0,-1,0,1 };
    std::deque<std::pair<int, int>> que;
    que.emplace_back(lmp[0], rmp[0]);
    tab[lmp[0]][rmp[0]] = 1;
    while (!que.empty()) {
        auto p = que.front();
        que.pop_front();
        for (int i = 0; i < 4; i++) {
            int x = p.first + d[i];
            int y = p.second + d[i + 1];
            if (!(0 <= x && x < cntl)) continue;
            if (!(0 <= y && y < cntr)) continue;
            if (tab[x][y] != 0) continue;
            tab[x][y] = 1;
            que.emplace_back(x, y);
        }
    }
    for (int i = 0; i < cntl; i++) {
        if (tab[i][0] == 1 || tab[i][cntr - 1] == 1) {
            std::cout << "INF" << std::endl;
            return 0;
        }
    }
    for (int i = 0; i < cntr; i++) {
        if (tab[0][i] == 1 || tab[cntl - 1][i] == 1) {
            std::cout << "INF" << std::endl;
            return 0;
        }
    }
    std::vector<std::vector<int>>
        valp(cntl, std::vector<int>(cntr)),
        valq(cntl, std::vector<int>(cntr));
    for (auto &p : lmp) for (auto &q : rmp) {
        valp[p.second][q.second] = p.first;
        valq[p.second][q.second] = q.first;
    }
    unsigned long long ans = 0;
    for (int i = 1; i < cntl; i++) {
        for (int j = 1; j < cntr; j++) {
            if (tab[i][j] == 1 || tab[i - 1][j] == 1
                || tab[i][j - 1] == 1 || tab[i - 1][j - 1] == 1) {
                ans += ((unsigned long long)valp[i][j] - valp[i - 1][j])
                    * ((unsigned long long)valq[i][j] - valq[i][j - 1]);
            }
        }
    }
    std::cout << ans/4 << std::endl;
    return 0;
}

Measured memory_bytes: 955188