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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FSingleDot {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n, m; cin >> n >> m;
      vector<ll> a(n), b(n), c(n);
      set<int> stx, sty;
      stx.insert(-1e+9-1);
      stx.insert(1e+9+1);
      stx.insert(0);
      sty.insert(-1e+9-1);
      sty.insert(1e+9+1);
      sty.insert(0);
      map<ll, int> mpx, mpy;
      rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
        stx.insert(a[i]);
        stx.insert(b[i]);
        sty.insert(c[i]);
      }
      vector<ll> d(m), e(m), f(m);
      rep(i, m) {
        cin >> d[i] >> e[i] >> f[i];
        stx.insert(d[i]);
        sty.insert(e[i]);
        sty.insert(f[i]);
      }

      int idx = 0;
      for(auto e: stx) {
        mpx[e] = idx;
        idx++;
      }
      int h = idx;
      idx = 0;
      for(auto e: sty) {
        mpy[e] = idx;
        idx++;
      }
      int w = idx;

      set<P, P> bann;

      vector<vector<int>> mat(2*h-1, vector<int>(2*w-1));
      rep(i, n) {
        auto ai = mpx[a[i]];
        auto bi = mpx[b[i]];
        auto ci = mpy[c[i]];
        for (auto j = ai * 2; j <= bi * 2; j++) {
          mat[j][ci * 2] = -1;
        }
      }
      rep(i, m) {
        auto di = mpx[d[i]];
        auto ei = mpy[e[i]];
        auto fi = mpy[f[i]];
        for(auto j = ei*2; j<=fi*2; j++) {
          mat[di*2][j] = -1;
        }
      }

      mat[mpx[0]*2][mpy[0]*2] = 1;

      /**
      for(auto e: mat) {
        for(auto f: e) {
          cerr << f << ' ';
        }
        cerr << endl;
      }*/

      stack<P> st;
      st.emplace(mpx[0]*2, mpy[0]*2);
      while(!st.empty()) {
        auto p = st.top(); st.pop();
        auto x = p.first;
        auto y = p.second;
        if (x > 0 && mat[x-1][y] == 0) {
          mat[x-1][y] = 1;
          st.emplace(x-1, y);
        }
        if (x+1 < 2*h-1 && mat[x+1][y] == 0) {
          mat[x+1][y] = 1;
          st.emplace(x+1, y);
        }
        if (y > 0 && mat[x][y-1] == 0) {
          mat[x][y-1] = 1;
          st.emplace(x, y-1);
        }
        if (y+1 < 2*w-1 && mat[x][y+1] == 0) {
          mat[x][y+1] = 1;
          st.emplace(x, y+1);
        }
      }

      vector<ll> revx(h);
      for(auto e: mpx) {
        revx[e.second] = e.first;
      }
      vector<ll> revy(w);
      for(auto e: mpy) {
        revy[e.second] = e.first;
      }

      ll ans = 0;

      for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
          if ((i==0 || i==2*(h-1)) && mat[i][j] == 1) {
            cout << "INF" << endl;
            return;
          }
          if ((j==0 || j==2*(w-1)) && mat[i][j] == 1) {
            cout << "INF" << endl;
            return;
          }
        }
      }

      for(int i=1; i<h-1; i++) {
        for(int j=1; j<w-1; j++) {
          if (mat[2*i+1][2*j+1] == 1) {
            ans += (revx[i+1]-revx[i])*(revy[j+1]-revy[j]);
          }
        }
      }
      cout << ans << endl;

    }
};

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

Measured memory_bytes: 305644