#include <bits/stdc++.h>
int R = 1, C = 1, H[2000010], N[2000010];
int hyouka(int a, int b) {
  if (C < b) return 1;
  if (C < a || b == 0) return 0;
  return N[H[a]] < N[H[b]] ? 1 : 0;
}
void hin(int a) {
  int i = C++;
  for (N[H[0] = R] = a; hyouka(0, i / 2); i /= 2) H[i] = H[i / 2];
  H[i] = R++;
}
int hout() {
  int rt = H[1], i, j = 2, k = H[--C];
  for (i = 1; hyouka(i, C); i = j)
    H[i] = H[j = i * 2 + 1 - hyouka(i * 2, i * 2 + 1)];
  H[j / 2] = k;
  return rt;
}
long long s[7010][7010], x[7000 * 7000], y[7000 * 7000];
int Y[] = {1, 0, -1, 0};
int X[] = {0, 1, 0, -1};
int main() {
  long long n, m, i, j, k, l, a[2010], b[2010], c[2010], d[6020], nx, ny, px,
      py, ans = 0, t = 0, r, z = 1;
  scanf("%lld %lld", &n, &m);
  hin(0);
  for (i = 0; i < n + m; i++) {
    scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
    hin(a[i]);
    hin(b[i]);
    hin(c[i]);
  }
  d[0] = N[hout()];
  for (i = z = 1; i < (n + m) * 3 + 1; i++) {
    d[z] = N[hout()];
    if (d[z] - d[z - 1]) z++;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; d[j] - a[i]; j++)
      ;
    for (k = 0; d[k] - b[i]; k++)
      ;
    for (l = 0; d[l] - c[i]; l++)
      ;
    for (j *= 2; j <= k * 2; j++) s[j][l * 2] = 1;
  }
  for (i = n; i < m + n; i++) {
    for (j = 0; d[j] - b[i]; j++)
      ;
    for (k = 0; d[k] - c[i]; k++)
      ;
    for (l = 0; d[l] - a[i]; l++)
      ;
    for (j *= 2; j <= k * 2; j++) s[l * 2][j] = 1;
  }
  for (i = 0; d[i]; i++)
    ;
  s[y[0] = i * 2][x[0] = i * 2] = 1;
  t = 0;
  for (r = 1; r - t; t++) {
    px = x[t];
    py = y[t];
    if (px % 2 == 0 || py % 2 == 0)
      ;
    else
      ans += (d[px / 2 + 1] - d[px / 2]) * (d[py / 2 + 1] - d[py / 2]);
    for (i = 0; i < 4; i++) {
      ny = py + Y[i];
      nx = px + X[i];
      if (ny < 0 || ny == z * 2 - 1 || nx < 0 || nx == z * 2 - 1) {
        printf("INF\n");
        return 0;
      }
      if (s[ny][nx] == 1) continue;
      s[y[r] = ny][x[r] = nx] = 1;
      r++;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
