#include <bits/stdc++.h>
using namespace std;
const long long N = 4005;
const long long INF = 1e10 + 5;
long long n, m;
long long a[N], b[N], c[N], d[N], e[N], f[N];
vector<long long> vx{-INF, INF}, vy{-INF, INF};
bool bu[N][N], bd[N][N], bl[N][N], br[N][N], vis[N][N];
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
bool check(long long x, long long y) {
  return x >= 0 && x < n && y >= 0 && y < n && !vis[x][y];
}
void bfs(long long x, long long y) {
  queue<pair<long long, long long> > q;
  vis[x][y] = true;
  q.push({x, y});
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    long long x = p.first;
    long long y = p.second;
    for (long long i = 0; i < 4; i++) {
      if ((i == 0 && bu[x][y]) || (i == 1 && bd[x][y]) ||
          (i == 2 && br[x][y]) || (i == 3 && bl[x][y]))
        continue;
      long long xn = x + dx[i];
      long long yn = y + dy[i];
      if (check(xn, yn)) {
        vis[xn][yn] = true;
        q.push({xn, yn});
      }
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) {
    cin >> n >> m;
    for (long long i = 0; i < n; i++) {
      cin >> a[i] >> b[i] >> c[i];
      vx.push_back(a[i]);
      vx.push_back(b[i]);
      vy.push_back(c[i]);
    }
    for (long long i = 0; i < m; i++) {
      cin >> d[i] >> e[i] >> f[i];
      vx.push_back(d[i]);
      vy.push_back(e[i]);
      vy.push_back(f[i]);
    }
    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());
    vx.resize(unique(vx.begin(), vx.end()) - vx.begin());
    vy.resize(unique(vy.begin(), vy.end()) - vy.begin());
    for (long long i = 0; i < n; i++) {
      long long la = lower_bound(vx.begin(), vx.end(), a[i]) - vx.begin();
      long long lb = lower_bound(vx.begin(), vx.end(), b[i]) - vx.begin();
      long long lc = lower_bound(vy.begin(), vy.end(), c[i]) - vy.begin();
      for (long long j = la; j < lb; j++) bu[j][lc - 1] = bd[j][lc] = true;
    }
    for (long long i = 0; i < m; i++) {
      long long ld = lower_bound(vx.begin(), vx.end(), d[i]) - vx.begin();
      long long le = lower_bound(vy.begin(), vy.end(), e[i]) - vy.begin();
      long long lf = lower_bound(vy.begin(), vy.end(), f[i]) - vy.begin();
      for (long long j = le; j < lf; j++) br[ld - 1][j] = bd[ld][j] = true;
    }
    long long x = --lower_bound(vx.begin(), vx.end(), 0) - vx.begin();
    long long y = --lower_bound(vy.begin(), vy.end(), 0) - vy.begin();
    bfs(x, y);
    cerr << x << ' ' << y << '\n';
    long long nx = vx.size();
    long long ny = vy.size();
    cerr << nx << ' ' << ny << '\n';
    if (vis[0][0] || vis[nx - 1][ny - 1]) return cout << "INF\n", 0;
    long long ans = 0;
    for (long long i = 0; i < nx - 1; i++) {
      for (long long j = 0; j < ny - 1; j++) {
        if (vis[i][j]) ans += (vx[i + 1] - vx[i]) * (vy[j + 1] - vy[j]);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
