#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template <typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int N = 1024, M = 4096;
ll a[N], b[N], c[N], d[N], e[N], f[N];
map<ll, int> xs = {{0, 0}}, ys = {{0, 0}};
ll xx[M], yy[M];
int p = 0, q = 0;
int h[M][M] = {}, v[M][M] = {};
bool u[M][M] = {};
queue<int> que;
void ad(int a, int b) {
  if (a < 0 || b < 0 || a >= p - 1 || b >= q - 1) {
    printf("INF\n");
    exit(0);
  }
  que.emplace(a * 4096 + b);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < ((n)); i++) {
    scanf("%lld%lld%lld", a + i, b + i, c + i);
    xs[a[i]];
    xs[b[i]];
    ys[c[i]];
  }
  for (int i = (0); i < ((m)); i++) {
    scanf("%lld%lld%lld", d + i, e + i, f + i);
    xs[d[i]];
    ys[e[i]];
    ys[f[i]];
  }
  for (auto &r : xs) xx[r.second = p++] = r.first;
  for (auto &r : ys) yy[r.second = q++] = r.first;
  for (int i = (0); i < ((n)); i++) {
    int y = ys[c[i]];
    h[y][xs[a[i]]]++;
    h[y][xs[b[i]]]--;
    ;
  }
  for (int i = (0); i < ((M)); i++)
    for (int j = (1); j < (M); j++) h[i][j] += h[i][j - 1];
  for (int i = (0); i < ((m)); i++) {
    int x = xs[d[i]];
    v[x][ys[e[i]]]++;
    v[x][ys[f[i]]]--;
    ;
  }
  for (int i = (0); i < ((M)); i++)
    for (int j = (1); j < (M); j++) v[i][j] += v[i][j - 1];
  ll ans = 0;
  ad(xs[0], ys[0]);
  while (que.size()) {
    int tp = que.front();
    que.pop();
    int i = tp / M, j = tp % M;
    if (u[i][j]) continue;
    u[i][j] = true;
    ;
    ans += (xx[i + 1] - xx[i]) * (yy[i + 1] - yy[i]);
    if (!v[i + 1][j]) ad(i + 1, j);
    if (!v[i][j]) ad(i - 1, j);
    if (!h[j + 1][i]) ad(i, j + 1);
    if (!h[j][i]) ad(i, j - 1);
  }
  printf("%lld\n", ans);
}
