/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class FSingleDot {
public:
    int N, M, H, W;
    vc<int> xs = {0}, ys = {0}, dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
    vc<pair<pii, int>> xsegs;
    vc<pair<int, pii>> ysegs;
    vvc<bool> used, grid;

    inline bool valid(int x, int y){
        return 0 <= x and x < H and 0 <= y and y < W;
    }

    inline void bfs(){
        queue<pii> que;
        int sx = 2 * (lower_bound(ALL(xs), 0) - xs.begin());
        int sy = 2 * (lower_bound(ALL(ys), 0) - ys.begin());
        used[sx][sy] = true;
        que.emplace(sx, sy);
        while(not que.empty()){
            int cx = que.front().first, cy = que.front().second;
            que.pop();
            REP(i, 4){
                int nx = cx + dx[i], ny = cy + dy[i];
                if(not valid(nx, ny) or not grid[nx][ny] or used[nx][ny]) continue;
                used[nx][ny] = true;
                que.emplace(nx, ny);
            }
        }
    }

    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        in>>N>>M;
        xsegs.resize(N);
        ysegs.resize(M);
        REP(i, N){
            in>>xsegs[i].first.first>>xsegs[i].first.second>>xsegs[i].second;
            int& a = xsegs[i].first.first, b = xsegs[i].first.second, c = xsegs[i].second;
            xs.pb(a);
            xs.pb(b);
            ys.pb(c);
        }
        REP(i, M){
            in>>ysegs[i].first>>ysegs[i].second.first>>ysegs[i].second.second;
            int& d = ysegs[i].first, e = ysegs[i].second.first, f = ysegs[i].second.second;
            xs.pb(d);
            ys.pb(e);
            ys.pb(f);
        }
        sort(ALL(xs));
        sort(ALL(ys));
        xs.erase(unique(ALL(xs)), xs.end());
        ys.erase(unique(ALL(ys)), ys.end());
        H = 2 * LEN(xs);
        W = 2 * LEN(ys);
        grid.resize(H, vc<bool>(W, true));
        used.resize(H, vc<bool>(W, false));
        REP(i, N){
            int& a = xsegs[i].first.first, b = xsegs[i].first.second, c = xsegs[i].second;
            int up = 2 * (lower_bound(ALL(xs), a) - xs.begin());
            int bottom = 2 * (lower_bound(ALL(xs), b) - xs.begin()) + 1;
            int y = 2 * (lower_bound(ALL(ys), c) - ys.begin());
            FOR(j, up, bottom) grid[j][y] = false;
        }
        REP(i, M){
            int& d = ysegs[i].first, e = ysegs[i].second.first, f = ysegs[i].second.second;
            int x = 2 * (lower_bound(ALL(xs), d) - xs.begin());
            int left = 2 * (lower_bound(ALL(ys), e) - ys.begin());
            int right = 2 * (lower_bound(ALL(ys), f) - ys.begin()) + 1;
            FOR(j, left, right) grid[x][j] = false;
        }
        bfs();
        lint ans = 0;
        REP(i, H) REP(j, W){
            if(not used[i][j]) continue;
            if(i==0 or i==H-1 or j==0 or j==W-1){
                out<<"INF\n";
                return;
            }
            if(i%2 and j%2) ans += 1ll * (xs[i/2+1]-xs[i/2]) * (ys[j/2+1]-ys[j/2]);
        }
        out<<ans<<'\n';
    }
};


int main() {
	FSingleDot solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 12684