#include <bits/stdc++.h>
using namespace std;
const int M = 1005;
const int INF = 1e9 + 5;
struct Node {
  int a, b, c;
  void read() { scanf("%d%d%d", &a, &b, &c); }
} r[M], c[M];
int x[M * 3], y[M * 3];
int nx, ny;
int findx(int v) { return lower_bound(x, x + nx, v) - x; }
int findy(int v) { return lower_bound(y, y + ny, v) - y; }
int vis[M * 3][M * 3];
int block[M * 3][M * 3][4];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
long long ans;
int qx[M * M * 9];
int qy[M * M * 9];
void bfs(int xx, int yy) {
  int t = 0;
  qx[t] = xx;
  qy[t] = yy;
  t++;
  vis[xx][yy] = 1;
  for (int ii = 0; ii < t; ii++) {
    xx = qx[ii];
    yy = qy[ii];
    ans += 1LL * (x[xx + 1] - x[xx]) * (y[yy + 1] - y[yy]);
    for (int i = 0; i < 4; i++) {
      if (block[xx][yy][i]) continue;
      int x = xx + dx[i], y = yy + dy[i];
      if (x <= 0 || nx - 1 <= x || y <= 0 || ny - 1 <= y) {
        ans = -1;
        return;
      }
      if (vis[x][y]) continue;
      vis[x][y] = 1;
      qx[t] = x;
      qy[t] = y;
      t++;
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  nx = ny = 0;
  for (int i = 0; i < n; i++) {
    r[i].read();
    x[nx++] = r[i].a;
    x[nx++] = r[i].b;
    y[ny++] = r[i].c;
  }
  for (int i = 0; i < m; i++) {
    c[i].read();
    x[nx++] = c[i].a;
    y[ny++] = c[i].b;
    y[ny++] = c[i].c;
  }
  x[nx++] = -INF;
  x[nx++] = INF;
  y[ny++] = -INF;
  y[ny++] = INF;
  sort(x, x + nx);
  nx = unique(x, x + nx) - x;
  sort(y, y + ny);
  ny = unique(y, y + ny) - y;
  for (int i = 0; i < n; i++) {
    int p = findy(r[i].c);
    for (int j = findx(r[i].a); j < findx(r[i].b); j++)
      block[j][p - 1][1] = block[j][p][0] = 1;
  }
  for (int i = 0; i < m; i++) {
    int p = findx(c[i].a);
    for (int j = findy(c[i].b); j < findy(c[i].c); j++)
      block[p - 1][j][3] = block[p][j][2] = 1;
  }
  bfs(findx(0), findy(0));
  if (ans == -1)
    printf("INF\n");
  else
    printf("%lld\n", ans);
  return 0;
}
