#include <bits/stdc++.h>
using namespace std;

#define ris   return *this
#define tmplt template<class T
#define dbgo  debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x;ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

#define lb(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())

const int mxN = 4005;
const int inf = 1e9+5;

int seen[mxN][mxN], no_up[mxN][mxN], no_down[mxN][mxN], no_left[mxN][mxN], no_right[mxN][mxN];
int a[mxN], b[mxN], c[mxN], d[mxN], e[mxN], f[mxN];
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
vector<int> xs{-inf, inf}, ys{-inf, inf};

void bfs(int x, int y) {
    vector<pair<int,int>> q{{x,y}};
    seen[x][y] = 1;
    forn(i, q.size()) {
        x = q[i].first, y = q[i].second;
        forn(k, 4) {
            if(k == 0 && no_left[x][y]) continue;
            if(k == 1 && no_down[x][y]) continue;
            if(k == 2 && no_up[x][y]) continue;
            if(k == 3 && no_right[x][y]) continue;
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(nx < 0 || ny < 0 || nx >= (int) xs.size() || ny >= (int) ys.size()) continue;
            if(seen[nx][ny]) continue;
            seen[nx][ny] = 1;
            q.emplace_back(nx, ny);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        xs.push_back(a[i]);
        xs.push_back(b[i]);
        ys.push_back(c[i]);
    }
    for(int i = 0; i < m; i++) {
        cin >> d[i] >> e[i] >> f[i];
        ys.push_back(e[i]);
        ys.push_back(f[i]);
        xs.push_back(d[i]);
    }
    sort(xs.begin(), xs.end());
    xs.resize(unique(xs.begin(), xs.end())-xs.begin());
    sort(ys.begin(), ys.end());
    ys.resize(unique(ys.begin(), ys.end())-ys.begin());
    int x = lb(xs, 0);
    int y = lb(ys, 0);
    x--, y--;
    debug() nav(x) nav(y);
    forn(i, n) {
        int aa = lb(xs, a[i]);
        int bb = lb(xs, b[i]);
        int cc = lb(ys, c[i]);
        for(int j = aa; j < bb; j++) {
            no_up[j][cc-1] = 1;
            no_down[j][cc] = 1;
        }
    }
    
    forn(i, m) {
        int dd = lb(xs, d[i]);
        int ee = lb(ys, e[i]);
        int ff = lb(ys, f[i]);
        for(int j = ee; j < ff; j++) {
            no_right[dd-1][j] = 1;
            no_left[dd][j] = 1;
        }
    }
    
    bfs(x, y);
    n = xs.size();
    m = ys.size();
    if(seen[0][0] || seen[n-1][m-1]) {
        cout << "INF\n";
        exit(0);
    }
    ll ans = 0;
    forn(i, n-1) forn(j, m-1) {
        if(seen[i][j]) {
            ans += 1LL * (xs[i+1]-xs[i]) * (ys[j+1]-ys[j]);
        }
    }
    cout << ans << endl;
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 277212