#include <bits/stdc++.h>
using namespace std;
int n, m;
int k[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int border[1010][1010][4];
int vis[1010][1010], qx[1010 * 1010], qy[1010 * 1010];
long long ans;
struct node {
  int a, b, c;
} f[1010], g[1010];
int X[1010], Y[1010], XN, YN;
int findX(int v) { return lower_bound(X, X + XN, v) - X; }
int findY(int v) { return lower_bound(Y, Y + YN, v) - Y; }
void bfs(int xx, int yy) {
  int i, h, t, nx, ny, x, y;
  h = t = 0;
  qx[t] = xx, qy[t] = yy, t++, vis[xx][yy] = 1;
  while (h < t) {
    x = qx[h], y = qy[h], h++;
    ans += (long long)(X[x + 1] - X[x]) * (Y[y + 1] - Y[y]);
    for (i = 0; i < 4; i++) {
      if (border[x][y][i]) continue;
      nx = x + k[i][0], ny = y + k[i][1];
      if (nx == 0 || nx == XN - 1 || ny == 0 || ny == YN - 1) {
        ans = -1;
        return;
      }
      if (vis[nx][ny]) continue;
      vis[nx][ny] = 1, qx[t] = nx, qy[t] = ny, t++;
    }
  }
}
void init() {
  int i, x, y, r, j;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++)
    scanf("%d%d%d", &f[i].a, &f[i].b, &f[i].c), X[XN++] = f[i].c;
  X[XN++] = -2000000000, X[XN++] = 2000000000;
  sort(X, X + XN);
  XN = unique(X, X + XN) - X;
  for (i = 0; i < m; i++)
    scanf("%d%d%d", &g[i].a, &g[i].b, &g[i].c), Y[YN++] = g[i].a;
  Y[YN++] = -2000000000, Y[YN++] = 2000000000;
  sort(Y, Y + YN);
  YN = unique(Y, Y + YN) - Y;
  for (i = 0; i < n; i++) {
    x = findX(f[i].c);
    r = findY(f[i].b);
    if (Y[r] != f[i].b) r--;
    for (j = findY(f[i].a); j < r; j++)
      border[x - 1][j][1] = border[x][j][0] = 1;
  }
  for (i = 0; i < m; i++) {
    y = findY(g[i].a);
    r = findX(g[i].c);
    if (X[r] != g[i].c) r--;
    for (j = findX(g[i].b); j < r; j++)
      border[j][y - 1][3] = border[j][y][2] = 1;
  }
}
int main() {
  init();
  bfs(findX(0) - 1, findY(0) - 1);
  if (ans == -1)
    printf("INF\n");
  else
    printf("%lld\n", ans);
  return 0;
}
