#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long a[1005], b[1005], c[1005], d[1005], e[1005], f[1005],
    up[1005][1005] = {0}, down[1005][1005] = {0}, left[1005][1005] = {0},
    right[1005][1005] = {0}, dir[5] = {-1, 0, 1, 0, -1};
bool used[1005][1005] = {0};
vector<long long> x, y;
queue<pair<long long, long long>> que;
long long id_x(long long v) {
  return lower_bound(x.begin(), x.end(), v) - x.begin() + 1;
}
long long id_y(long long v) {
  return lower_bound(y.begin(), y.end(), v) - y.begin() + 1;
}
int main() {
  long long i, j, n, m;
  scanf("%lld%lld", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
    x.emplace_back(a[i]);
    x.emplace_back(b[i]);
    y.emplace_back(c[i]);
  }
  for (i = 0; i < m; i++) {
    scanf("%lld%lld%lld", &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 (i = 0; i < n; i++) {
    a[i] = id_x(a[i]);
    b[i] = id_x(b[i]);
    c[i] = id_y(c[i]);
    for (j = a[i]; j < b[i]; j++) {
      up[j][c[i] - 1] = 1;
      down[j][c[i]] = 1;
    }
  }
  for (i = 0; i < m; i++) {
    d[i] = id_x(d[i]);
    e[i] = id_y(e[i]);
    f[i] = id_y(f[i]);
    for (j = e[i]; j < f[i]; j++) {
      right[d[i] - 1][j] = 1;
      left[d[i]][j] = 1;
    }
  }
  que.push({id_x(0), id_y(0)});
  used[id_x(0)][id_y(0)] = 1;
  while (que.size()) {
    auto z = que.front();
    que.pop();
    for (i = 0; i < 4; i++) {
      long long r = z.first + dir[i], c = z.second + dir[i + 1];
      if (r <= 0 || c <= 0 || r > x.size() || c > y.size() || used[r][c] ||
          (!i && left[r][c]) || (i == 1 && up[r][c]) ||
          (i == 2 && right[r][c]) || (i == 3 && down[r][c]))
        continue;
      used[r][c] = 1;
      que.push({r, c});
    }
  }
  for (i = 1; i <= x.size(); i++) {
    if (used[i][1] || used[i][y.size()]) {
      puts("INF");
      return 0;
    }
  }
  for (i = 1; i <= y.size(); i++) {
    if (used[1][i] || used[x.size()][i]) {
      puts("INF");
      return 0;
    }
  }
  long long ans = 0;
  for (i = 1; i < x.size(); i++) {
    for (j = 1; j < y.size(); j++) {
      if (used[i][j]) ans += (x[i + 1] - x[i]) * (y[i + 1] - y[i]);
    }
  }
  printf("%lld\n", ans);
}
