#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6005;
int a[MAXN], b[MAXN], c[MAXN], d[MAXN], e[MAXN], f[MAXN], x[MAXN], y[MAXN];
bool dw[MAXN][MAXN], lef[MAXN][MAXN], vis[MAXN][MAXN];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int cntx = 0, cnty = 0;
  x[++cntx] = 0, y[++cnty] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    x[++cntx] = a[i], x[++cntx] = b[i], y[++cnty] = c[i];
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &d[i], &e[i], &f[i]);
    x[++cntx] = d[i], y[++cnty] = e[i], y[++cnty] = f[i];
  }
  sort(x + 1, x + cntx + 1);
  cntx = unique(x + 1, x + cntx + 1) - (x + 1);
  sort(y + 1, y + cnty + 1);
  cnty = unique(y + 1, y + cnty + 1) - (y + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(x + 1, x + cntx + 1, a[i]) - x;
    b[i] = lower_bound(x + 1, x + cntx + 1, b[i]) - x;
    c[i] = lower_bound(y + 1, y + cnty + 1, c[i]) - y;
    for (int j = a[i]; j < b[i]; j++) dw[j][c[i]] = 1;
  }
  for (int i = 1; i <= m; i++) {
    d[i] = lower_bound(x + 1, x + cntx + 1, d[i]) - x;
    e[i] = lower_bound(y + 1, y + cnty + 1, e[i]) - y;
    f[i] = lower_bound(y + 1, y + cnty + 1, f[i]) - y;
    for (int j = e[i]; j < f[i]; j++) lef[d[i]][j] = 1;
  }
  int sx = lower_bound(x + 1, x + cntx + 1, 0) - x;
  int sy = lower_bound(y + 1, y + cnty + 1, 0) - y;
  queue<pair<int, int>> q;
  q.push({sx, sy});
  while (!q.empty()) {
    int nx, ny;
    tie(nx, ny) = q.front();
    q.pop();
    if (vis[nx][ny]) continue;
    vis[nx][ny] = 1;
    if (ny > 0 && !dw[nx][ny]) q.push({nx, ny - 1});
    if (nx > 0 && !lef[nx][ny]) q.push({nx - 1, ny});
    if (ny < cnty && !dw[nx][ny + 1]) q.push({nx, ny + 1});
    if (nx < cntx && !lef[nx + 1][ny]) q.push({nx + 1, ny});
  }
  long long res = 0;
  for (int i = 0; i <= cntx; i++)
    for (int j = 0; j <= cnty; j++)
      if (vis[i][j]) {
        if (i == 0 || i == cntx || j == 0 || j == cnty)
          return 0 * printf("INF\n");
        res += 1LL * (x[i + 1] - x[i]) * (y[i + 1] - y[i]);
      }
  return 0 * printf("%lld\n", res);
}
