// ※※※ 解答不能 ※※※
// snuke氏.
// https://atcoder.jp/contests/abc168/submissions/13357090
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<int, int>;
using vvi = vector<vector<int>>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define a first
#define b second
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

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

int main(){
    int n, m;
    map<int, int> mpX, mpY;
    vector<L> lh, lv;
    scanf("%d %d", &n, &m);
    mpX[0] = 0;
    mpY[0] = 0;
    
    rep(i, n){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        mpX[a] = 0;
        mpX[b] = 0;
        mpY[c] = 0;
        lh.emplace_back(a, b, c);
    }
    rep(i, m){
        int a, b, c;
        scanf("%d %d %d", &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.b = xs.size();
        xs.pb(p.a);
    }
    for(auto &p : mpY){
        p.b = ys.size();
        ys.pb(p.a);
    }
    int h = xs.size() * 2;
    int w = ys.size() * 2;
    vvi d(h, vector<int>(w));
    rep(i, n){
        int a = mpX[lh[i].a] * 2;
        int b = mpX[lh[i].b] * 2;
        int c = mpY[lh[i].c] * 2;
        repx(x, a, b + 1) d[x][c] = -1;
    }
    rep(i, m){
        int a = mpY[lv[i].a] * 2;
        int b = mpY[lv[i].b] * 2;
        int c = mpX[lv[i].c] * 2;
        repx(y, a, b + 1) d[c][y] = -1;
    }
    
    queue<P> 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().a;
        int y = q.front().b;
        q.pop();
        rep(v, 4){
            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);
        }
    }
    
    LL ans = 0;
    rep(x, h){
        rep(y, w){
            if(d[x][y] != 1) continue;
            if(x == 0 || x == h - 1 || y == 0 || y == w - 1){
                puts("INF");
                return 0;
            }
            if(x % 2 == 0 || y % 2 == 0) continue;
            LL ex = xs[x / 2 + 1] - xs[x / 2];
            LL ey = ys[y / 2 + 1] - ys[y / 2];
            ans += ex * ey;
        }
    }
    printf("%lld\n", ans);
    return 0;
}