#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007; 
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}






int main(){
    int N, M; std::cin >> N >> M;
    std::vector<int> A(N), B(N), C(N), D(M), E(M), F(M);
    std::map<int, int> mX, mY;
    mX[0]; mY[0];
    for(int i(0); i < N; ++i){
        std::cin >> A[i] >> B[i] >> C[i];
        mX[A[i]]; mX[B[i]]; mY[C[i]];
    }
    for(int i(0); i < M; ++i){
        std::cin >> D[i] >> E[i] >> F[i];
        mX[D[i]]; mY[E[i]]; mY[F[i]];
    }

    std::vector<int> xx, yy;
    for(auto &p: mX){
        p.second = xx.size();
        xx.push_back(p.first);
    }
    for(auto &p: mY){
        p.second = yy.size();
        yy.push_back(p.first);
    }

    int H(xx.size() * 2), W(yy.size() * 2);
    //-1: 壁、1: 到達可能
    std::vector<std::vector<int>> reach(H, std::vector<int>(W, 0));
    for(int i(0); i < N; ++i){
        int a(mX[A[i]] * 2), b(mX[B[i]] * 2), c(mY[C[i]] * 2);
        for(int x(a); x <= b; ++x) reach[x][c] = -1;
    }
    for(int i(0); i < M; ++i){
        int d(mX[D[i]] * 2), e(mY[E[i]] * 2), f(mY[F[i]] * 2);
        for(int y(e); y <= f; ++y) reach[d][y] = -1;
    }

    int dx[4] = {0, -1, 0, 1};
    int dy[4] = {1, 0, -1, 0};
    std::queue<std::pair<int, int>> que;
    int sx(mX[0] * 2), sy(mY[0] * 2);
    reach[sx][sy] = 1;
    que.emplace(sx, sy);
    while(!que.empty()){
        auto p(que.front());
        int x(p.first), y(p.second);
        que.pop();
        for(int i(0); i < 4; ++i){
            int nx(x + dx[i]), ny(y + dy[i]);
            if(nx < 0 || nx >= H || ny < 0 || ny >= W || reach[nx][ny] != 0){
                continue;
            }
            if(!nx || nx == H-1 || !ny || ny == W-1){
                std::cout << "INF" << std::endl;
                return 0;
            }
            reach[nx][ny] = 1;
            que.emplace(nx, ny);
        }
    }

    long long ans(0);
    for(int x(0); x < H; ++x){
        for(int y(0); y < W; ++y){
            if(reach[x][y] != 1) continue;
            if(!(x % 2) || !(y % 2)) continue;
            long long ex(xx[x/2 + 1] - xx[x/2]), ey(yy[y/2 + 1] - yy[y/2]);
            ans += ex * ey;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 144420