#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  // line segments
  struct LSS {
    int p;
    vector<pair<int, int>> s;

    LSS(int p = 0) :p(p) {}

    static bool leftCmp(const pair<int, int>& l, const pair<int, int>& r)
    {
      return l.first < r.first;
    }

    void Add(int start, int end) {
      pair<int, int> e = { start, end };
      int x = lower_bound(rng(s), e, leftCmp) - s.begin();

      int erasex, erasecnt = 0;
      if (x > 0 && s[x - 1].se >= e.fi) {
        e.first = s[x - 1].first;
        chmax(e.second, s[x - 1].second);
        erasecnt++;
        erasex = x - 1;
      }
      while (x < s.size() && s[x].first <= e.second) {
        chmax(e.second, s[x].second);
        if (!erasecnt) erasex = x;
        erasecnt++;
        x++;
      }
      if (erasecnt) {
        s.erase(s.begin() + erasex, s.begin() + erasex + erasecnt);
        s.insert(s.begin() + erasex, e);
      }
      else {
        s.insert(s.begin() + x, e);
      }
    }

    bool hitCheck(int start, int end) {
      pair<int, int> e = { start+1, end };
      int x = lower_bound(rng(s), e, leftCmp) - s.begin();
      if (--x < 0) return false;

      if (s[x].first <= start && end <= s[x].second) {
        return true;
      }
      return false;
    }
  };

  struct LS {
    int p, s, e;
    LS(int p = 0, int s = 0, int e = 0) :p(p), s(s), e(e) {}
  };

  auto lsCmp = [](const LS& l, const LS& r) {
    return l.p < r.p;
  };


  vector<LS> vls(N), hls(M);

  F0R(i, N) {
    cin >> vls[i].s >> vls[i].e >> vls[i].p;
  }
  F0R(i, M) {
    cin >> hls[i].p >> hls[i].s >> hls[i].e;
  }

  i64 result = 0;
  if (M > 1 && N > 1) {
    sort(rng(hls), lsCmp);
    sort(rng(vls), lsCmp);

    vector<LSS> vs, hs;

    auto ls2lss = [](vector<LSS>& lss, const vector<LS>& ls) {
      F0R(i, ls.size()) {
        if (lss.size() == 0 || ls[i].p != lss.back().p) {
          lss.emplace_back(ls[i].p);
        }
        lss.back().Add(ls[i].s, ls[i].e);
      }
    };
    ls2lss(vs, vls);
    ls2lss(hs, hls);

    // print vs, hs
#if 0
    F0R(i, vs.size()) {
      F0R(j, vs[i].s.size()) {
        cout << vs[i].p << "," << vs[i].s[j].first << "~" << vs[i].s[j].second << newl;
      }
    }
    F0R(i, hs.size()) {
      F0R(j, hs[i].s.size()) {
        cout << hs[i].s[j].first << "~" << hs[i].s[j].second << "," << hs[i].p << newl;
      }
    }
#endif

    auto lssCmp = [](const LSS& l, const LSS& r) {
      return l.p < r.p;
    };

    int mx = lower_bound(rng(vs), LSS(0), lssCmp) - vs.begin();
    int my = lower_bound(rng(hs), LSS(0), lssCmp) - hs.begin();

    vector<vector<bool>> vis(M - 1, vector<bool>(N - 1, false));

    queue<pair<int, int>> qu;
    qu.emplace(mx, my);

    // bfs
    while (qu.size()) {
      int x, y;
      tie(x, y) = qu.front();
      qu.pop();
      int px = x - 1, py = y - 1;
      if (px < 0 || py < 0 || x > vs.size() - 1 || y > hs.size() - 1) {
        result = 0; // INF
        break;
      }

      if (vis[py][px]) continue;
      //cout << x << "," << y << newl;
      //cout << "(" << vs[px].p << " ~ " << vs[x].p << ", " << hs[py].p << " ~ " << hs[y].p << ")" << newl;



      vis[py][px] = true;
      
      result += ((i64)vs[x].p - vs[px].p) * ((i64)hs[y].p - hs[py].p);

      if (!hs[py].hitCheck(vs[px].p, vs[x].p)) qu.emplace(x, y - 1);
      if (!vs[px].hitCheck(hs[py].p, hs[y].p)) qu.emplace(x - 1, y);
      if (!hs[y].hitCheck(vs[px].p, vs[x].p)) qu.emplace(x, y + 1);
      if (!vs[x].hitCheck(hs[py].p, hs[y].p)) qu.emplace(x + 1, y);

    }
  }

  if (result == 0) cout << "INF";
  else cout << result;
}
#endif


Measured memory_bytes: 3996