/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=2e9;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

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

int n, m;

void solve() {
	cin >> n >> m;
    vector<int> xs = {-INF, INF}, ys = {-INF, INF};
    auto add = [&](int x, int y) {
        xs.push_back(x);
        ys.push_back(y);
    };
    vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
    rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
        add(a[i], c[i]);
        add(b[i], c[i]);
    }
    rep(i, m) {
        cin >> d[i] >> e[i] >> f[i];
        add(d[i], e[i]);
        add(d[i], f[i]);
    }
    xs = compress(xs);
    ys = compress(ys);
    int xsz = (int)xs.size(), ysz = (int)ys.size();
    
    auto find_x = [&](int x)->int{ return upper_bound(all(xs), x) - xs.begin() - 1; };
    auto find_y = [&](int y)->int{ return upper_bound(all(ys), y) - ys.begin() - 1; };

    static bitset<3100> above[3100], left[3100];

    rep(i, n) {
        a[i] = find_x(a[i]);
        b[i] = find_x(b[i]);
        c[i] = find_y(c[i]);
        for(int x = a[i]; x < b[i]; ++ x) {
            left[x][c[i]] = 1;
        }
    }
    rep(i, m) {
        d[i] = find_x(d[i]);
        e[i] = find_y(e[i]);
        f[i] = find_y(f[i]);
        for(int y = e[i]; y < f[i]; ++ y) {
            above[d[i]][y] = 1;
        }
    }
    int cowx = find_x(0), cowy = find_y(0);
    vector<vector<int>> dist(xsz, vector<int>(ysz, INF));
    dist[cowx][cowy] = 0;
    queue<P> que;
    que.push(P{cowx, cowy});
    auto check = [&](int x, int y)->bool{ return (0 <= x && x < xsz && 0 <= y && y < ysz); };
    while(!que.empty()) {
        P p = que.front(); que.pop();
        int x = p.fr, y = p.sc;
        //left
        if(check(x, y - 1) && !left[x][y] && chmin(dist[x][y - 1], dist[x][y] + 1)) {
            que.push(P{x, y - 1});
        }
        //above
        if(check(x - 1, y) && !above[x][y] && chmin(dist[x - 1][y], dist[x][y] + 1)) {
            que.push(P{x - 1, y});
        }
        //right
        if(check(x, y + 1) && !left[x][y + 1] && chmin(dist[x][y + 1], dist[x][y] + 1)) {
            que.push(P{x, y + 1});
        }
        //down
        if(check(x + 1, y) && !above[x + 1][y] && chmin(dist[x + 1][y], dist[x][y] + 1)) {
            que.push(P{x + 1, y});
        }
    }
    int ans = 0;
    rep(i, xsz - 1) {
        rep(j, ysz - 1) {
            int dx = xs[i + 1] - xs[i], dy = ys[j + 1] - ys[j];
            if(dist[i][j] < INF) {
                if(i == 0 || j == 0 || i == xsz - 2 || j == ysz - 2) {
                    cout << "INF" << endl;
                    return;
                }
                ans += dx * dy;
            }
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 76340