#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, i, j, k, x, y, xx, yy, ans, cc, nn, mm;
  cin >> n >> m;
  vector<long long> a(n), b(n), c(n), d(m), e(m), f(m);
  set<long long> sx = {-1000000100, 0, 1000000100, 1000000200};
  set<long long> sy = {-1000000100, 0, 1000000100, 1000000200};
  for (i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    sx.insert(a[i]);
    sx.insert(b[i]);
    sy.insert(c[i]);
  }
  for (i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    sx.insert(d[i]);
    sy.insert(e[i]);
    sy.insert(f[i]);
  }
  map<long long, long long> xid, yid;
  cc = 0;
  for (auto p : sx) xid[p] = cc++;
  cc = 0;
  for (auto p : sy) yid[p] = cc++;
  nn = yid.size();
  mm = xid.size();
  vector<long long> xsize(mm), ysize(nn);
  vector<long long> px, py;
  for (auto p : sx) px.push_back(p);
  for (auto p : sy) py.push_back(p);
  for (i = 0; i < mm - 1; i++) xsize[i] = px[i + 1] - px[i];
  for (i = 0; i < nn - 1; i++) ysize[i] = py[i + 1] - py[i];
  vector<vector<bool>> up(nn, vector<bool>(mm, true));
  vector<vector<bool>> down(nn, vector<bool>(mm, true));
  vector<vector<bool>> left(nn, vector<bool>(mm, true));
  vector<vector<bool>> right(nn, vector<bool>(mm, true));
  for (i = 0; i < nn; i++) {
    left[i][0] = false;
    right[i][mm - 1] = false;
  }
  for (i = 0; i < mm; i++) {
    down[0][i] = false;
    up[nn - 1][i] = false;
  }
  for (i = 0; i < n; i++) {
    x = xid[a[i]];
    xx = xid[b[i]];
    y = yid[c[i]];
    for (j = x; j < xx; j++) {
      down[y][j] = false;
      up[y - 1][j] = false;
    }
  }
  for (i = 0; i < m; i++) {
    x = xid[d[i]];
    y = yid[e[i]];
    yy = yid[f[i]];
    for (j = y; j < yy; j++) {
      right[j][x - 1] = false;
      left[j][x] = false;
    }
  }
  vector<vector<bool>> visited(nn, vector<bool>(mm, false));
  x = xid[0];
  y = yid[0];
  queue<pair<int, int>> q;
  visited[x][y] = true;
  q.push({x, y});
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    vector<pair<long long, long long>> v;
    if (right[x][y]) v.push_back({x, y + 1});
    if (left[x][y]) v.push_back({x, y - 1});
    if (down[x][y]) v.push_back({x - 1, y});
    if (up[x][y]) v.push_back({x + 1, y});
    for (auto p : v) {
      xx = p.first;
      yy = p.second;
      if (visited[xx][yy]) continue;
      visited[xx][yy] = true;
      q.push({xx, yy});
    }
  }
  if (visited[0][0])
    cout << "INF\n";
  else {
    ans = 0;
    for (i = 0; i < nn; i++) {
      for (j = 0; j < mm; j++) {
        if (visited[i][j]) ans += ysize[i] * xsize[j];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
