#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1005], b[1005], c[1005];
int d[1005], e[1005], f[1005];
int G[3005][3005];
int vis[3005][3005];
long long ans = 0;
int w[3005], h[3005];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
vector<int> _X, _Y;
unordered_map<int, int> _mX, _mY;
queue<pair<int, int> > q;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    _X.emplace_back(a[i]);
    _X.emplace_back(b[i]);
    _Y.emplace_back(c[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &d[i], &e[i], &f[i]);
    _X.emplace_back(d[i]);
    _Y.emplace_back(e[i]);
    _Y.emplace_back(f[i]);
  }
  _X.emplace_back(0);
  _Y.emplace_back(0);
  sort(_X.begin(), _X.end());
  sort(_Y.begin(), _Y.end());
  _X.erase(unique(_X.begin(), _X.end()), _X.end());
  _Y.erase(unique(_Y.begin(), _Y.end()), _Y.end());
  for (int i = 0; i < _X.size(); i++) _mX[_X[i]] = i;
  for (int i = 0; i < _Y.size(); i++) _mY[_Y[i]] = i;
  for (int i = 0; i < _X.size() - 1; i++) {
    h[i * 2 + 2] = _X[i + 1] - _X[i];
  }
  for (int i = 0; i < _Y.size() - 1; i++) {
    w[i * 2 + 2] = _Y[i + 1] - _Y[i];
  }
  for (int i = 0; i < n; i++) {
    a[i] = 2 * _mX[a[i]] + 1;
    b[i] = 2 * _mX[b[i]] + 1;
    c[i] = 2 * _mY[c[i]] + 1;
    for (int J = a[i]; J <= b[i]; J++) {
      G[J][c[i]] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    d[i] = 2 * _mX[d[i]] + 1;
    e[i] = 2 * _mY[e[i]] + 1;
    f[i] = 2 * _mY[f[i]] + 1;
    for (int J = e[i]; J <= f[i]; J++) {
      G[d[i]][J] = 1;
    }
  }
  int sx = 2 * _mX[0] + 1;
  int sy = 2 * _mY[0] + 1;
  q.push({sx, sy});
  vis[sx][sy] = 1;
  while (q.size()) {
    int x, y;
    tie(x, y) = q.front();
    q.pop();
    for (int k = 0; k < 4; k++) {
      int nx = x + dx[k], ny = y + dy[k];
      if (G[nx][ny] == 0 && vis[nx][ny] == 0) {
        vis[nx][ny] = 1;
        if (nx == 0 || ny == 0 || nx == 2 * _X.size() || ny == 2 * _Y.size()) {
          printf("INF");
          return 0;
        }
        q.push({nx, ny});
        ans += (long long)h[nx] * w[ny];
      }
    }
  }
  printf("%lld", ans);
}
