#include <bits/stdc++.h>
using namespace std;
long long inf = 1001001001;
vector<long long> x, y;
int xn, ynum;
long long a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
bool xb[3010][3010], yb[3010][3010], sumi[3010][3010];
int main() {
  int n, m;
  x.push_back(0);
  y.push_back(0);
  x.push_back(inf);
  y.push_back(inf);
  x.push_back(-inf);
  y.push_back(-inf);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    x.push_back(a[i]);
    x.push_back(b[i]);
    y.push_back(c[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    x.push_back(d[i]);
    y.push_back(e[i]);
    y.push_back(f[i]);
  }
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  sort(y.begin(), y.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  xn = x.size();
  ynum = y.size();
  memset(xb, false, sizeof(xb));
  memset(yb, false, sizeof(yb));
  for (int i = 0; i < n; i++) {
    int xs = lower_bound(x.begin(), x.end(), a[i]) - x.begin();
    int xg = lower_bound(x.begin(), x.end(), b[i]) - x.begin();
    int ys = lower_bound(y.begin(), y.end(), c[i]) - y.begin();
    for (int j = xs; j < xg; j++) yb[j][ys] = true;
  }
  for (int i = 0; i < m; i++) {
    int xs = lower_bound(x.begin(), x.end(), d[i]) - x.begin();
    int ys = lower_bound(y.begin(), y.end(), e[i]) - y.begin();
    int yg = lower_bound(y.begin(), y.end(), f[i]) - y.begin();
    for (int j = ys; j < yg; j++) xb[xs][j] = true;
  }
  memset(sumi, false, sizeof(sumi));
  queue<pair<int, int> > q;
  q.push(make_pair(lower_bound(x.begin(), x.end(), 0L) - x.begin(),
                   lower_bound(y.begin(), y.end(), 0L) - y.begin()));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int u = p.first, v = p.second;
    sumi[u][v] = true;
    if (u > 0 && !xb[u][v] && !sumi[u - 1][v])
      q.push(make_pair(u - 1, v)), sumi[u - 1][v] = true;
    if (v > 0 && !yb[u][v] && !sumi[u][v - 1])
      q.push(make_pair(u, v - 1)), sumi[u][v - 1] = true;
    if (u < xn - 2 && !xb[u + 1][v] && !sumi[u + 1][v])
      q.push(make_pair(u + 1, v)), sumi[u + 1][v] = true;
    if (v < ynum - 2 && !yb[u][v + 1] && !sumi[u][v + 1])
      q.push(make_pair(u, v + 1)), sumi[u][v + 1] = true;
  }
  long long out = 0;
  for (int i = 0; i < xn - 1; i++)
    for (int j = 0; j < ynum - 1; j++) {
      if (sumi[i][j]) out += (x[i + 1] - x[i]) * (y[j + 1] - y[j]);
    }
  if (out >= inf * inf)
    cout << "INF" << endl;
  else
    cout << out << endl;
}
