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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int32 dx[4] = {0,1,0,-1};
int32 dy[4] = {1,0,-1,0};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,m;
  cin >> n >> m;
  vector<int32> a(n),b(n),c(n);
  vector<int32> d(m),e(m),f(m);
  map<int32,int32> compx,compy;
  compx[0] = -1;
  compy[0] = -1;
  REP(i,n){
    cin >> a[i] >> b[i] >> c[i];
    compx[a[i]] = -1;
    compx[b[i]] = -1;
    compy[c[i]] = -1;
  }
  REP(i,m){
    cin >> d[i] >> e[i] >> f[i];
    compx[d[i]] = -1;
    compy[e[i]] = -1;
    compy[f[i]] = -1;
  }
  vector<int32> decx,decy;
  for(auto& p : compx){
    p.second = decx.size();
    decx.pb(p.first);
  }
  for(auto& p : compy){
    p.second  = decy.size();
    decy.pb(p.first);
  }

  int32 h = decx.size() * 2;
  int32 w = decy.size() * 2;
  vector<vector<int32>> dist(h, vector<int32>(w,INF));
  REP(i,n){
    int32 ca = compx[a[i]] * 2;
    int32 cb = compx[b[i]] * 2;
    int32 cc = compy[c[i]] * 2;
    FOR(j,ca,cb+1){
      dist[j][cc] = -1;
    }
  }
  REP(i,m){
    int32 cd = compx[d[i]] * 2;
    int32 ce = compy[e[i]] * 2;
    int32 cf = compy[f[i]] * 2;
    FOR(j,ce,cf+1){
      dist[cd][j] = -1;
    }
  }

  queue<pii> que;
  que.emplace(compx[0]*2,compy[0]*2);
  dist[compx[0]*2][compy[0]*2] = 0;
  while(!que.empty()){
    auto [cx,cy] = que.front();que.pop();
    REP(k,4){
      int32 nx = cx + dx[k];
      int32 ny = cy + dy[k];
      if(nx < 0 || h <= nx || ny < 0 || w <= ny){
        ANS("INF");
        return 0;
      }
      if(dist[nx][ny] != INF)continue;
      dist[nx][ny] = 0;
      que.emplace(nx,ny);
    }
  }
  int64 ans = 0;
  REP(k,h/2-1)REP(l,w/2-1){
    int32 i = k*2+1;
    int32 j = l*2+1;
    if(dist[i][j] != 0)continue;
    int32 dx = decx[k+1] - decx[k];
    int32 dy = decy[l+1] - decy[l];
    ans += dx * dy;
  }
  ANS(ans);
  return 0;
}