#include <bits/stdc++.h>

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


struct line {
    i32 a1,a2,b;
    line (i32 a1, i32 a2, i32 b): a1(a1), a2(a2), b(b) {}
};

i32 mv_x[] = {1,0,-1,0};
i32 mv_y[] = {0,1,0,-1};
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n,m, tmp; cin >> n >> m;
    map<i32, i32> mp_x, mp_y;  // mp< real-coordinate, compressed-coordinate >
    mp_x[0] = 0, mp_y[0] = 0;
    vec<line> line_h, line_v;  // horizontal line and vertical line
    rep(i,n) {
        i32 a,b,c; cin >> a >> b >> c;
        mp_x[a] = 0;
        mp_x[b] = 0;
        mp_y[c] = 0;
        line_h.emplace_back(a,b,c);
    }
    rep(i,m) {
        i32 d,e,f; cin >> d >> e >> f;
        mp_x[d] = 0;
        mp_y[e] = 0;
        mp_y[f] = 0;
        line_v.emplace_back(e,f,d);
    }

    // decide compressed coordinate
    vi xs, ys;
    tmp = 0;
    for(auto &p : mp_x) {
        xs.push_back(p.first);
        p.second = tmp;
        ++tmp;
    }
    tmp = 0;
    for(auto &p : mp_y) {
        ys.push_back(p.first);
        p.second = tmp;
        ++tmp;
    }

    i32 w = ys.size() * 2, h = xs.size() * 2;
    vii grid(h, vi(w));

    // write
    rep(i,n) {
        i32 x1 = mp_x[line_h[i].a1] * 2;
        i32 x2 = mp_x[line_h[i].a2] * 2;
        i32 y = mp_y[line_h[i].b] * 2;
        for(i32 x = x1; x <= x2; ++x) grid[x][y] = -1;
    }
    rep(i,m) {
        i32 y1 = mp_y[line_v[i].a1] * 2;
        i32 y2 = mp_y[line_v[i].a2] * 2;
        i32 x = mp_x[line_v[i].b] * 2;
        for(i32 y = y1; y <= y2; ++y) grid[x][y] = -1;
    }

    // bfs
    queue<PII> que;
    i32 sx = mp_x[0] * 2;
    i32 sy = mp_y[0] * 2;
    grid[sx][sy] = 1;
    que.emplace(sx, sy);
    while(que.size()) {
        i32 x, y;
        tie(x,y) = que.front(); que.pop();
        rep(i, 4) {
            i32 nx = x + mv_x[i];
            i32 ny = y + mv_y[i];
            if(!(0 <= nx && nx < h && 0 <= ny && ny < w)) continue;
            if(grid[nx][ny] != 0) continue;
            grid[nx][ny] = 1;
            que.emplace(nx, ny);
        }
    }

    i64 ans = 0;
    rep(i, h)rep(j, w) {
        if(grid[i][j] != 1) continue;
        if(i <= 0 || i > h || j <= 0 || j > w) {
            cout << "INF" << '\n';
            return 0;
        }
        if(i%2==0 || j%2==0) continue;
        i32 H = xs[i/2 + 1] - xs[i/2];
        i32 W = ys[j/2 + 1] - ys[j/2];

        ans += H*W;
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 285440