#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = 3000 + 7;
const ll LIM = (ll) 1e9 + 7;
int n, m, a[N], b[N], c[N], d[N], e[N], f[N];
map<int, int> idr, idc;

struct Cell {
  int r1;
  int c1;
  int r2;
  int c2;
};

Cell cell[N][N];
bool zid1[N][N];
bool zid2[N][N];
bool vis[N][N];

void clr() {
  for (int i = 1; i <= 100; i++) {
    cout << "\n";
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i] >> c[i];
   /// cout << "Segment " << a[i] << " " << c[i] << " " << b[i] << " " << c[i] << "\n";
  }
  for (int i = 1; i <= m; i++) {
    cin >> d[i] >> e[i] >> f[i];
   /// cout << "Segment " << d[i] << " " << e[i] << " " << d[i] << " " << f[i] << "\n";
  }
  ///clr();
  set<int> rows, cols;
  for (int i = 1; i <= n; i++) {
    rows.insert(a[i]);
    rows.insert(b[i]);
  }
  for (int i = 1; i <= m; i++) {
    rows.insert(d[i]);
  }
  for (int i = 1; i <= n; i++) {
    cols.insert(c[i]);
  }
  for (int i = 1; i <= m; i++) {
    cols.insert(e[i]);
    cols.insert(f[i]);
  }
  rows.insert(-LIM);
  rows.insert(+LIM);
  cols.insert(-LIM);
  cols.insert(+LIM);
  vector<int> vecRows, vecCols;
  for (auto &x : rows) {
    vecRows.push_back(x);
  }
  for (auto &x : cols) {
    vecCols.push_back(x);
  }
  for (int i = 0; i < (int) rows.size(); i++) {
    idr[vecRows[i]] = i;
  }
  for (int i = 0; i < (int) cols.size(); i++) {
    idc[vecCols[i]] = i;
  }
  int dimr = (int) vecRows.size() - 1, dimc = (int) vecCols.size() - 1;
  for (int i = 1; i <= dimr; i++) {
    for (int j = 1; j <= dimc; j++) {
      cell[i][j] = {vecRows[i - 1], vecCols[j - 1], vecRows[i] - 1, vecCols[j] - 1};
    }
  }
  for (int i = 1; i <= n; i++) {
    int pos = idc[c[i]];
    int lo = idr[a[i]] + 1;
    int hi = idr[b[i]] + 1;
    for (int j = lo; j < hi; j++) {
      zid1[j][pos] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    int pos = idr[d[i]];
    int lo = idc[e[i]] + 1;
    int hi = idc[f[i]] + 1;
    for (int j = lo; j < hi; j++) {
      zid2[pos][j] = 1;
    }
  }
  int ri, ci;
  for (int i = 1; i <= dimr; i++) {
    for (int j = 1; j <= dimc; j++) {
      if (cell[i][j].r1 <= 0 && 0 <= cell[i][j].r2 && cell[i][j].c1 <= 0 && 0 <= cell[i][j].c2) {
        ri = i;
        ci = j;
      }
    }
  }
  queue<pair<int, int>> q;
  q.push({ri, ci});
  vis[ri][ci] = 1;
  while (!q.empty()) {
    pair<int, int> it = q.front();
    q.pop();
    int r = it.first, c = it.second;
    if (c - 1 >= 1 && zid1[r][c - 1] == 0 && !vis[r][c - 1]) {
      vis[r][c - 1] = 1;
      q.push({r, c - 1});
    }
    if (c + 1 <= dimc && zid1[r][c] == 0 && !vis[r][c + 1]) {
      ///cout << "aici 2\n";
      vis[r][c + 1] = 1;
      q.push({r, c + 1});
    }
    if (r - 1 >= 1 && zid2[r - 1][c] == 0 && !vis[r - 1][c]) {
      ///cout << "aici 3\n";
      vis[r - 1][c] = 1;
      q.push({r - 1, c});
    }
    if (r + 1 <= dimr && zid2[r][c] == 0 && !vis[r + 1][c]) {
     /// cout << "aici 4\n";
      vis[r + 1][c] = 1;
      q.push({r + 1, c});
    }
   /// return 0;
  }
  ll sol = 0;
  for (int i = 1; i <= dimr; i++) {
    for (int j = 1; j <= dimc; j++) {
      if (vis[i][j]) {
        if (i == 1 || i == dimr || j == 1 || j == dimc) {
          cout << "INF\n";
          return 0;
        }
        ll deltaR = cell[i][j].r2 - cell[i][j].r1 + 1;
        ll deltaC = cell[i][j].c2 - cell[i][j].c1 + 1;
        sol += deltaR * deltaC;
      }
    }
  }
  cout << sol << "\n";
  return 0;
}


Measured memory_bytes: 168408