#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  bool f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 0;
  for (; isdigit(c); c = getchar()) x = x * 10 + (c & 15);
  if (!f) x = -x;
}
const int maxn = 2e3 + 5;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int n, m;
int a[maxn], b[maxn], c[maxn];
int d[maxn], e[maxn], f[maxn];
int scol[maxn][maxn], srow[maxn][maxn];
bool vis[maxn][maxn];
int que[maxn * maxn * 2 + 5], ql, qr;
vector<int> vx, vy;
bool ok[maxn][maxn][4];
int main() {
  read(n);
  read(m);
  for (int i = 0; i < (int)(n); ++i) read(a[i]), read(b[i]), read(c[i]);
  for (int i = 0; i < (int)(m); ++i) read(d[i]), read(e[i]), read(f[i]);
  for (int i = 0; i < (int)(n); ++i)
    vx.push_back(a[i]), vx.push_back(b[i]), vy.push_back(c[i]);
  for (int i = 0; i < (int)(m); ++i)
    vx.push_back(d[i]), vy.push_back(e[i]), vy.push_back(f[i]);
  vx.push_back(0);
  vy.push_back(0);
  vx.push_back(inf);
  vy.push_back(inf);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  for (int i = 0; i < (int)(n); ++i)
    a[i] = (lower_bound((vx).begin(), (vx).end(), (a[i])) - (vx).begin()),
    b[i] = (lower_bound((vx).begin(), (vx).end(), (b[i])) - (vx).begin()),
    c[i] = (lower_bound((vy).begin(), (vy).end(), (c[i])) - (vy).begin());
  for (int i = 0; i < (int)(m); ++i)
    d[i] = (lower_bound((vx).begin(), (vx).end(), (d[i])) - (vx).begin()),
    e[i] = (lower_bound((vy).begin(), (vy).end(), (e[i])) - (vy).begin()),
    f[i] = (lower_bound((vy).begin(), (vy).end(), (f[i])) - (vy).begin());
  int sx = (lower_bound((vx).begin(), (vx).end(), (0)) - (vx).begin()),
      sy = (lower_bound((vy).begin(), (vy).end(), (0)) - (vy).begin());
  for (int i = 0; i < (int)(n); ++i) scol[a[i]][c[i]]++, scol[b[i]][c[i]]--;
  for (int i = 0; i < (int)(m); ++i) srow[d[i]][e[i]]++, srow[d[i]][f[i]]--;
  for (int i = 0; i < (int)(vx.size()); ++i)
    for (int j = 0; j < (int)(vy.size()); ++j)
      if (i) scol[i][j] += scol[i - 1][j];
  for (int i = 0; i < (int)(vx.size()); ++i)
    for (int j = 0; j < (int)(vy.size()); ++j)
      if (j) srow[i][j] += srow[i][j - 1];
  for (int i = 0; i < (int)(vx.size() - 1); ++i)
    for (int j = 0; j < (int)(vy.size() - 1); ++j) {
      if (srow[i][j])
        ok[i][j][0] = 0;
      else
        ok[i][j][0] = 1;
      if (srow[i + 1][j])
        ok[i][j][1] = 0;
      else
        ok[i][j][1] = 1;
      if (scol[i][j])
        ok[i][j][2] = 0;
      else
        ok[i][j][2] = 1;
      if (scol[i][j + 1])
        ok[i][j][3] = 0;
      else
        ok[i][j][3] = 1;
    }
  vis[sx][sy] = 1;
  que[qr++] = sx;
  que[qr++] = sy;
  long long ans = 0;
  while (ql < qr) {
    int x = que[ql++], y = que[ql++];
    ans += 1LL * (vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
    for (int d = 0; d < (int)(4); ++d) {
      if (!ok[x][y][d]) continue;
      int nx = x + dx[d], ny = y + dy[d];
      if (nx < 0 || ny < 0 || nx >= vx.size() - 1 || ny >= vy.size() - 1) {
        puts("INF");
        return 0;
      }
      if (!vis[nx][ny]) {
        vis[nx][ny] = 1;
        que[qr++] = nx;
        que[qr++] = ny;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
