#include <bits/stdc++.h>
int n, m;
int a[1010][2], b[1010][2], c[1010][2];
int d[1010][2], e[1010][2], f[1010][2];
long long x[(1010 * 3)], y[(1010 * 3)];
int xcnt, ycnt;
int result[(1010 * 2)][(1010 * 2)];
void printDir(int x, int y, int d) {
  printf("(%d %d) => %d", x, y, d);
  if (d & 2) printf(" UP");
  if (d & 1) printf(" DOWN");
  if (d & 8) printf(" LEFT");
  if (d & 4) printf(" RIGHT");
  printf("\n");
}
int cmpfunc(const void *a, const void *b) {
  return (*((long long *)a) - *((long long *)b));
}
int sort(long long d[], int n) {
  int c = 0;
  qsort(d, n, sizeof(long long), cmpfunc);
  for (int i = 1; i < n; i++) {
    if (d[i] != d[c]) {
      d[++c] = d[i];
    }
  }
  return (c + 1);
}
int srch(int a, long long d[], int n) {
  int l = 0;
  int r = n - 1;
  while (r - l > 1) {
    int c = (l + r) / 2;
    if (a < d[c])
      r = c;
    else
      l = c;
  }
  return (l);
}
int checkWall(int cx, int cy) {
  int result = 0;
  for (int i = 0; i < n; i++) {
    if (cx < a[i][1]) continue;
    if (cx >= b[i][1]) continue;
    if (cy == c[i][1]) result |= 1;
    if (cy == c[i][1] - 1) result |= 2;
  }
  for (int i = 0; i < m; i++) {
    if (cy < e[i][1]) continue;
    if (cy >= f[i][1]) continue;
    if (cx == d[i][1]) result |= 8;
    if (cx == d[i][1] - 1) result |= 4;
  }
  return (result);
}
int main() {
  long long tot = 0;
  clock_t start = clock();
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &a[i][0], &b[i][0], &c[i][0]);
    x[xcnt++] = a[i][0];
    x[xcnt++] = b[i][0];
    y[ycnt++] = c[i][0];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &d[i][0], &e[i][0], &f[i][0]);
    x[xcnt++] = d[i][0];
    y[ycnt++] = e[i][0];
    y[ycnt++] = f[i][0];
  }
  x[xcnt++] = y[ycnt++] = -1e9;
  x[xcnt++] = y[ycnt++] = 1e9;
  x[xcnt++] = y[ycnt++] = 0;
  xcnt = sort(x, xcnt);
  ycnt = sort(y, ycnt);
  for (int i = 0; i < n; i++) {
    a[i][1] = srch(a[i][0], x, xcnt);
    b[i][1] = srch(b[i][0], x, xcnt);
    c[i][1] = srch(c[i][0], y, ycnt);
  }
  for (int i = 0; i < m; i++) {
    d[i][1] = srch(d[i][0], x, xcnt);
    e[i][1] = srch(e[i][0], y, ycnt);
    f[i][1] = srch(f[i][0], y, ycnt);
  }
  int cx = srch(0, x, xcnt);
  int cy = srch(0, y, ycnt);
  int cuex[2][1010];
  int cuey[2][1010];
  int cuenum[2] = {1, 0};
  int cuesel = 0;
  int cuenext;
  cuex[cuesel][0] = cx;
  cuey[cuesel][0] = cy;
  result[cx][cy] = 1;
  tot += (x[cx + 1] - x[cx]) * (y[cy + 1] - y[cy]);
  for (int r = 1; r < 100; r++) {
    cuenext = 1 - cuesel;
    cuenum[cuenext] = 0;
    if (cuenum[cuesel] == 0) break;
    for (int i = 0; i < cuenum[cuesel]; i++) {
      cx = cuex[cuesel][i];
      cy = cuey[cuesel][i];
      int wall = checkWall(cx, cy);
      if (!(wall & 8) && cx > 0) {
        cuex[cuenext][cuenum[cuenext]] = cx - 1;
        cuey[cuenext][cuenum[cuenext]] = cy;
        if (result[cx - 1][cy] == 0) {
          cuenum[cuenext]++;
          result[cx - 1][cy] = r + 1;
          tot += (x[cx] - x[cx - 1]) * (y[cy + 1] - y[cy]);
        }
      }
      if (!(wall & 4) && cx < xcnt) {
        cuex[cuenext][cuenum[cuenext]] = cx + 1;
        cuey[cuenext][cuenum[cuenext]] = cy;
        if (result[cx + 1][cy] == 0) {
          cuenum[cuenext]++;
          result[cx + 1][cy] = r + 1;
          tot += (x[cx + 2] - x[cx + 1]) * (y[cy + 1] - y[cy]);
        }
      }
      if (!(wall & 1) && cy > 0) {
        cuex[cuenext][cuenum[cuenext]] = cx;
        cuey[cuenext][cuenum[cuenext]] = cy - 1;
        if (result[cx][cy - 1] == 0) {
          cuenum[cuenext]++;
          result[cx][cy - 1] = r + 1;
          tot += (x[cx + 1] - x[cx]) * (y[cy] - y[cy - 1]);
        }
      }
      if (!(wall & 2) && cy < ycnt) {
        cuex[cuenext][cuenum[cuenext]] = cx;
        cuey[cuenext][cuenum[cuenext]] = cy + 1;
        if (result[cx][cy + 1] == 0) {
          cuenum[cuenext]++;
          result[cx][cy + 1] = r + 1;
          tot += (x[cx + 1] - x[cx]) * (y[cy + 2] - y[cy + 1]);
        }
      }
    }
    cuesel = 1 - cuesel;
    if (cuenum[cuesel] == 0) break;
  }
  if (result[0][0] > 0)
    puts("INF");
  else
    printf("%lld\n", tot);
}
