#include <bits/stdc++.h>
using namespace std;
const int X = 1e9 + 1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
void ff(const vector<vector<bool> > &down, const vector<vector<bool> > &right,
        vector<vector<bool> > &s, int x, int y) {
  if (s[x][y]) {
    return;
  }
  s[x][y] = true;
  if (x < s.size() - 1 && !down[x][y]) {
    ff(down, right, s, x + 1, y);
  }
  if (x >= 1 && !down[x - 1][y]) {
    ff(down, right, s, x - 1, y);
  }
  if (y < s[0].size() - 1 && !right[x][y]) {
    ff(down, right, s, x, y + 1);
  }
  if (y >= 1 && !right[x][y - 1]) {
    ff(down, right, s, x, y - 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[n], b[n], c[n];
  vector<int> mx, my;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    mx.push_back(a[i]);
    mx.push_back(b[i]);
    my.push_back(c[i]);
  }
  int d[m], e[m], f[m];
  for (int i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    mx.push_back(d[i]);
    my.push_back(e[i]);
    my.push_back(f[i]);
  }
  mx.push_back(-X);
  mx.push_back(0);
  mx.push_back(X);
  my.push_back(-X);
  my.push_back(0);
  my.push_back(X);
  sort(mx.begin(), mx.end());
  mx.resize(unique(mx.begin(), mx.end()) - mx.begin());
  sort(my.begin(), my.end());
  my.resize(unique(my.begin(), my.end()) - my.begin());
  int xsz = mx.size() - 1, ysz = my.size() - 1;
  vector<vector<bool> > s(xsz, vector<bool>(ysz)), down(xsz, vector<bool>(ysz)),
      right(xsz, vector<bool>(ysz));
  for (int i = 0; i < n; i++) {
    int xa = lower_bound(mx.begin(), mx.end(), a[i]) - mx.begin();
    int xb = lower_bound(mx.begin(), mx.end(), b[i]) - mx.begin();
    int yc = lower_bound(my.begin(), my.end(), c[i]) - my.begin();
    for (int j = xa; j < xb; j++) {
      down[j][yc - 1] = true;
    }
  }
  for (int i = 0; i < m; i++) {
    int xd = lower_bound(mx.begin(), mx.end(), d[i]) - mx.begin();
    int ye = lower_bound(my.begin(), my.end(), e[i]) - my.begin();
    int yf = lower_bound(my.begin(), my.end(), f[i]) - my.begin();
    for (int j = ye; j < yf; j++) {
      right[xd - 1][j] = true;
    }
  }
  int x0 = lower_bound(mx.begin(), mx.end(), 0) - mx.begin();
  int y0 = lower_bound(my.begin(), my.end(), 0) - my.begin();
  ff(right, down, s, x0, y0);
  long long ans = 0;
  for (int i = 0; i < xsz; i++) {
    for (int j = 0; j < ysz; j++) {
      if (s[i][j]) {
        if (i == 0 || i == xsz - 1 || j == 0 || j == ysz - 1) {
          cout << "INF" << endl;
          return 0;
        }
        ans += 1ll * (mx[i + 1] - mx[i]) * (my[j + 1] - my[j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
