#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5005;
int a[N], b[N], c[N];
int d[N], e[N], f[N];
long long sz[N][N];
bool lef[N][N], rig[N][N], up[N][N], dow[N][N];
bool vis[N][N];
queue<pair<int, int> > bf;
int is, js;
vector<int> ii, jj;
void add(int ii, int jj) {
  if (ii < 0 || ii >= is - 1 || jj < 0 || jj >= js - 1) {
    cout << "INF\n";
    exit(0);
  }
  if (vis[ii][jj]) return;
  vis[ii][jj] = true;
  bf.push(make_pair(ii, jj));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    jj.push_back(c[i]);
    ii.push_back(a[i]);
    ii.push_back(b[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    ii.push_back(d[i]);
    jj.push_back(e[i]);
    jj.push_back(f[i]);
  }
  ii.push_back(-(int)2e9);
  ii.push_back(0);
  ii.push_back((int)2e9);
  jj.push_back(-(int)2e9);
  jj.push_back(0);
  jj.push_back((int)2e9);
  sort(ii.begin(), ii.end());
  sort(jj.begin(), jj.end());
  ii.resize(unique(ii.begin(), ii.end()) - ii.begin());
  jj.resize(unique(jj.begin(), jj.end()) - jj.begin());
  is = ii.size();
  js = jj.size();
  for (int i = 0; i + 1 < is; i++) {
    for (int j = 0; j + 1 < js; j++) {
      lef[i][j] = rig[i][j] = up[i][j] = dow[i][j] = true;
      sz[i][j] = (ii[i + 1] - ii[i]) * 1ll * (jj[j + 1] - jj[j]);
    }
  }
  int l, r, cm;
  for (int i = 0; i < n; i++) {
    l = lower_bound(ii.begin(), ii.end(), a[i]) - ii.begin();
    r = lower_bound(ii.begin(), ii.end(), b[i]) - ii.begin();
    cm = lower_bound(jj.begin(), jj.end(), c[i]) - jj.begin();
    for (int k = l + 1; k <= r; k++) {
      rig[k][cm - 1] = lef[k][cm] = false;
    }
  }
  for (int i = 0; i < m; i++) {
    l = lower_bound(jj.begin(), jj.end(), e[i]) - jj.begin();
    r = lower_bound(jj.begin(), jj.end(), f[i]) - jj.begin();
    cm = lower_bound(ii.begin(), ii.end(), d[i]) - ii.begin();
    for (int k = l; k < r; k++) {
      dow[cm + 1][k] = up[cm][k] = false;
    }
  }
  int ic, jc;
  ic = lower_bound(ii.begin(), ii.end(), 0) - ii.begin();
  jc = lower_bound(jj.begin(), jj.end(), 0) - jj.begin();
  add(ic, jc);
  add(ic + 1, jc);
  add(ic, jc - 1);
  add(ic + 1, jc - 1);
  while (!bf.empty()) {
    ic = bf.front().first;
    jc = bf.front().second;
    bf.pop();
    if (lef[ic][jc]) add(ic, jc - 1);
    if (rig[ic][jc]) add(ic, jc + 1);
    if (up[ic][jc]) add(ic + 1, jc);
    if (dow[ic][jc]) add(ic - 1, jc);
  }
  long long ans = 0;
  for (int i = 0; i + 1 < is; i++) {
    for (int j = 0; j + 1 < js; j++) {
      if (vis[i][j]) ans += sz[i][j];
    }
  }
  cout << ans << "\n";
  return 0;
}
