#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &t) {
  t = 0;
  char ch = getchar();
  int f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  do {
    (t *= 10) += ch - '0';
    ch = getchar();
  } while ('0' <= ch && ch <= '9');
  t *= f;
}
const int INF = (1e9) + 10;
int N, M, n, m, dx[3010], dy[3010];
int a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
long long ans;
bool vis[3010][3010], heng[3010][3010], shu[3010][3010];
int Fx(int x) { return lower_bound(dx + 1, dx + n + 1, x) - dx; }
int Fy(int y) { return lower_bound(dy + 1, dy + m + 1, y) - dy; }
void dfs(int x, int y) {
  if (x <= 2 || x == n || y <= 2 || y == m) {
    printf("INF\n");
    exit(0);
  }
  if (vis[x][y]) return;
  vis[x][y] = 1;
  ans += (long long)(dx[x] - dx[x - 1]) * (dy[y] - dy[y - 1]);
  if (!heng[x][y]) dfs(x, y + 1);
  if (!heng[x][y - 1]) dfs(x, y - 1);
  if (!shu[x][y]) dfs(x - 1, y);
  if (!shu[x + 1][y]) dfs(x + 1, y);
}
int main() {
  read(N);
  read(M);
  dx[++n] = 0, dy[++m] = 0;
  dx[++n] = -INF, dx[++n] = INF;
  dy[++m] = -INF, dy[++m] = INF;
  for (int i = 1; i <= N; i++) {
    read(a[i]);
    read(b[i]);
    read(c[i]);
    dx[++n] = a[i], dx[++n] = b[i], dy[++m] = c[i];
  }
  for (int i = 1; i <= M; i++) {
    read(d[i]);
    read(e[i]);
    read(f[i]);
    dx[++n] = d[i], dy[++m] = e[i], dy[++m] = f[i];
  }
  sort(dx + 1, dx + n + 1);
  sort(dy + 1, dy + m + 1);
  n = unique(dx + 1, dx + n + 1) - dx - 1;
  m = unique(dy + 1, dy + m + 1) - dy - 1;
  for (int i = 1; i <= N; i++) {
    a[i] = Fx(a[i]), b[i] = Fx(b[i]), c[i] = Fy(c[i]);
    for (int j = a[i]; j < b[i]; j++) heng[j][c[i]] = 1;
  }
  for (int i = 1; i <= M; i++) {
    d[i] = Fx(d[i]), e[i] = Fy(e[i]), f[i] = Fy(f[i]);
    for (int j = e[i] + 1; j <= f[i]; j++) shu[d[i]][j] = 1;
  }
  int x = Fx(0), y = Fy(0);
  dfs(x, y);
  printf("%lld\n", ans);
  return 0;
}
