//                                       _____   ---===--   _____
//                             .    ''                              ``  -.
//                      .  '                                                  `   .
//                   .'       _ _  _                                                  ` .
//                 /  ' '                 ''    -- .                                       `\
//                |                                      ` -.                                /\
//                 \ ______  -----   ____                       ` -.                        .'|_
//                  \\mmmNNNNNNNNNNNNmm==____`   - . _                `.`  -  .......  - '  . ' |
//                   |"""""""""""""MNNNNNNNNNNNNNNNm==___ `  -  . _     \   .---====-- .. '     |
//                   -''''''''''' `   -  __   '"""MMNNNNNNNNNNNmm===______ "|       __  | | NN) (
//                 / ::::::::::::::::::::::::::`  -  .  __ '"""MNNNNNNNNNNNNN\   (NNN*  | |__...J
//               /  ::::::::::::::::::::::::::::::::::::::::::` -  .  __  '"""\       . ''|      ` .
//             /    :::::::::::::::::::::::::::::::::::::::::::::::::::  '''' / -- ' /  |::\  \ ,)   `.
//            /    ::'   ':::::::::/:::::::::::::::::::::''::  :::   ::::::::/    ( /   |:::\   "" _. ''
//           /    ::'   :/:'  ::  /    :::::    :::     :. .::\:::::::::::::< _        /::::::\  /\
//          / .:::::::::/::...:. /     :::::....:::::::::::::::\:::::::::::::::\:`:-  /::::\::::`:N\
//         / ::/:::::::/::::::::/::::::::::::::::::::::::::::::::\:::::::\::::::|::::|::::::|::::::N\
//        | ::|:::::::|:::::::/ |:::::::::/|:::::::::/:::::\::::::\:::::::\:::::|::::|:::::::|::::::N|
//        | ::|:::::::|::::::/  |:|::::::| |::::::::| |:::::\::::::\:::::::|:::/:::::]::::::::::::::N\
//        | ::|:::::::|:::::/   |:|::::::| |::::::::|  \:::::\\:::::\::::::|::/:::::/:::::::/:::::::NN|
//        | ::|:::::::|::::|     \:\:::::|  \::::::::\ --\::::\_\::::|:::::|:/:::::/:::::::/::::::::NN|
//         |::|:::::::|::::|-'""""\:\:::|    \::\-::::\   `-|\:\  `-:|:::::|:::::::::::::/:::::|:::::N|
//         |::|::::\::\::\::|  ___ \ `-_:\     "-\ `-__  --'''___;_   |::::|:::::::::.m'\:::::::|::::N|
//          \::\::::|:::\:\--\___  `- ` '"        ""   ggmm@@@@@@@@@m ):::/:::::::. @@XXL|:::::::\:::N|
//           \::\::::\:::\mN**@@@@@mm                  \    |::TT:::/::::/N:::::/ @@@@XXL|::::::::\::NN\
//            \N:NN\:::-.::\  |::TT::|                  ` . _\:::::/ /::7NN:::/::|@@@@XXL|:::::::::\::NN\
//             \NNN\\'n-:`N\ - \::::/                             / / /NN::::/:::|@@@XXL/:::::::::::\::NN\
//              `"NN\ `-NN''\                                    _7 "  \:::::\::|LXXXLL/:::::::::::::`.NNN\
//                `-NN\ \NNNN\                                          |\::::\:|<LLLL/\:::::::::::::\::`NN\
//                    ` '|NNNN\          '                             /NNN`m- >NN|::\NN\:::::\:::::::\:::::`.
//                       |NNNNNN\                                   .i'/:::::::/NN|:::\NN\::::::\:::::::\::::::`;-.
//                      |NNNNNN/:/`.          .__.              . '  |/::/::::/NNN|:::::\N\:::::::`.:::::`Nn::::::::`m-.
//                     /NNNNN/:n/:::|` .                    . '      /::y::::/NN::N|:::\::\|:::::::::`.:::::"-.::::::::::`m.
//                    /NNN.':://::::|NNNN/` .          . '          /:::/:::/"""">NN\::::\:::`.:::::.:::::::::::`-.:::::::::)
//                  /."':::.'N::::::|NNN/::\::__`'''\              /::::::::|@@@@||NN\::::::::::`.::::` .::::::::::::`.-.::/
//              -'::::::m':/:::::::/NN/:::::|ffffrrrrmmmmmmmm@@@@@|:::::::\N|@@@| \:\N\::::::::::::`.:::::`.::::::::::::::::`..
//           /::::::m'::.':::::/::/"':::::/ /\fffffffffffff@@@@@@@|::::::::\|@@@| N`.\NN`.::::::::::::`.:::::`-.::::::::.:::::::` .
//           \::::mT:':::::::/:.':::::::,'/MMM\N.   ffffffff    @@|:::::::::\@@/.  NNNNNNNNN`m.:::::::::"=::::::"Nn:::::::`.::::::::`.
//          -':':::::::::::.':/:::::::://MMM. ""*fffffffffffffffff@\:::::::::\"   gg`  -  . NNNN\`n.::::::".::::::"N:::::::"n::::::::|
//    .- ':::.:::::::.':.':::/::::::::/- ' Mng      """"""""""      `\::|::::::\M*",,,,,,,,,,,,` .\\N`.::::|:::::::|::::::::|:::::::/
// /':::::.'::::::.'::/::::n/::::::::|,,,,,, "**++g,,________,,,,,,mmm\::\:::::::\,,,,,,,,,,,,gnNN" ` .N)::/::.:::|::::::|::N|:::.''
//|:::. '::::::n":::/":::N" \:\::::::|,,,,,,,,,,,,,**/NN/*******,,,,,,,,`.|`.:::::|,,,,,, gnN*."'       \:.:::|::::\::::::\nN::/
//.|::::::::,n":::,":::,N    \:\:::::\,,,,,,,,,,,,,,/NN/,,,,,,,,,,,,,,,,,,|   `.  |ggnN**"   /           |::::|::::::::::::\Nm:|

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

typedef long long ll;
typedef pair<ll,ll> P;
ll const INF = 2e9;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n,m,l = 0;
    cin >> n >> m;
    vector<int> a(n),b(n),c(n),d(m),e(m),f(m),aa(n),bb(n),cc(n),dd(m),ee(m),ff(m);
    map<int,int> mp;
    for (int i = 0;i < n;++i) cin >> a[i] >> b[i] >> c[i];
    for (int i = 0;i < m;++i) cin >> d[i] >> e[i] >> f[i];
    for (int i = 0;i < n;++i) mp[a[i]];
    for (int i = 0;i < n;++i) mp[b[i]];
    for (int i = 0;i < n;++i) mp[c[i]];
    for (int i = 0;i < m;++i) mp[d[i]];
    for (int i = 0;i < m;++i) mp[e[i]];
    for (int i = 0;i < m;++i) mp[f[i]];
    mp[0];
    mp[-INF];
    mp[INF];
    for (auto& p : mp) p.second = l++;
    vector<ll> s(l);
    for (int i = 0;i < n;++i) aa[i] = mp[a[i]];
    for (int i = 0;i < n;++i) bb[i] = mp[b[i]];
    for (int i = 0;i < n;++i) cc[i] = mp[c[i]];
    for (int i = 0;i < m;++i) dd[i] = mp[d[i]];
    for (int i = 0;i < m;++i) ee[i] = mp[e[i]];
    for (int i = 0;i < m;++i) ff[i] = mp[f[i]];
    for (auto p : mp) s[p.second] = p.first;
    vector<vector<bool>> u(l,vector<bool>(l,true)),v(l,vector<bool>(l,true));
    for (int i = 0;i < n;++i) for (int j = aa[i];j < bb[i];++j) u[j][cc[i]] = false;
    for (int i = 0;i < m;++i) for (int j = ee[i];j < ff[i];++j) v[dd[i]][j] = false;
    queue<P> que;
    vector<vector<bool>> used(l,vector<bool>(l,false));
    que.push({mp[0],mp[0]});
    used[mp[0]][mp[0]] = true;
    ll ans = 0;
    while (!que.empty()) {
        P t = que.front();que.pop();
        if (t.first == 0 || t.first == l-1 || t.second == 0 || t.second == l-1) {
            ans = -1;
            break;
        }
        ans += (s[t.first+1]-s[t.first])*(s[t.second+1]-s[t.second]);
        if (u[t.first][t.second] && !used[t.first][t.second-1]) {
            que.push({t.first,t.second-1});
            used[t.first][t.second-1] = true;
        }
        if (u[t.first][t.second+1] && !used[t.first][t.second+1]) {
            que.push({t.first,t.second+1});
            used[t.first][t.second+1] = true;
        }
        if (v[t.first][t.second] && !used[t.first-1][t.second]) {
            que.push({t.first-1,t.second});
            used[t.first-1][t.second] = true;
        }
        if (v[t.first+1][t.second] && !used[t.first+1][t.second]) {
            que.push({t.first+1,t.second});
            used[t.first+1][t.second] = true;
        }
    }
    if (ans < 0) cout << "INF" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17700