#include <bits/stdc++.h>
using namespace std;
map<int, int> mpx, mpy;
int invx[14000], invy[14000], bias = 7000;
int a[1111], b[1111], c[1111], d[1111], e[1111], f[1111];
bool vis[14000][14000], l[14000][14000];
long long ans = 0;
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
bool is_inf;
void dfs(int x, int y) {
  if (is_inf) return;
  if (x > 6500 || x < -6500 || y > 6500 || y < -6500) {
    is_inf = 1;
    return;
  }
  if (vis[x + bias][y + bias]) {
    return;
  }
  vis[x + bias][y + bias] = 1;
  long long tmpx, tmpy;
  if (x % 2) {
    tmpx = 0;
  } else {
    tmpx = invx[x + 1 + bias] - invx[x - 1 + bias];
  }
  if (y % 2) {
    tmpy = 0;
  } else {
    tmpy = invy[y + 1 + bias] - invy[y - 1 + bias];
  }
  ans += tmpx * tmpy;
  if (l[x + bias][y + bias]) {
    return;
  }
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    dfs(xx, yy);
  }
}
set<int> xx[2], yy[2];
int main() {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < n; ++i) {
      scanf("%d%d%d", a + i, b + i, c + i);
      xx[a[i] > 0].insert(a[i]);
      xx[b[i] > 0].insert(b[i]);
      yy[c[i] > 0].insert(c[i]);
    }
    for (int i = 0; i < m; ++i) {
      scanf("%d%d%d", d + i, e + i, f + i);
      xx[d[i] > 0].insert(d[i]);
      yy[e[i] > 0].insert(e[i]);
      yy[f[i] > 0].insert(f[i]);
    }
    int cnt = -1;
    for (set<int>::reverse_iterator it = xx[0].rbegin(); it != xx[0].rend();
         ++it) {
      mpx[*it] = cnt;
      invx[cnt + bias] = *it;
      cnt -= 2;
    }
    cnt = 1;
    for (auto it : xx[1]) {
      mpx[it] = cnt;
      invx[cnt + bias] = it;
      cnt += 2;
    }
    cnt = -1;
    for (set<int>::reverse_iterator it = yy[0].rbegin(); it != yy[0].rend();
         ++it) {
      mpy[*it] = cnt;
      invy[cnt + bias] = *it;
      cnt -= 2;
    }
    cnt = 1;
    for (auto it : yy[1]) {
      mpy[it] = cnt;
      invy[cnt + bias] = it;
      cnt += 2;
    }
    for (int i = 0; i < n; ++i) {
      int tmp = mpy[c[i]];
      for (int j = mpx[a[i]]; j <= mpx[b[i]]; ++j) {
        l[j + bias][tmp + bias] = 1;
      }
    }
    for (int i = 0; i < m; ++i) {
      int tmp = mpx[d[i]];
      for (int j = mpy[e[i]]; j <= mpy[f[i]]; ++j) {
        l[tmp + bias][j + bias] = 1;
      }
    }
    ans = 0;
    is_inf = 0;
    dfs(0, 0);
    if (is_inf) {
      printf("INF\n");
    } else
      printf("%lld\n", ans);
  }
  return 0;
}
