#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18;
struct node {
  int s = 1;
  int e = 1;
  int n = 1;
  int w = 1;
  int mark = 0;
} net[1001][1001];
long long linesn[1001], lineew[1001], lsn_cnt, lew_cnt, sn0, ew0;
struct seg {
  int pos;
  int fr;
  int to;
  bool operator<(const seg& se) const { return pos < se.pos; }
} sn[1001], ew[1001];
int n, m, a, b, c;
int bfind_min(long long* s, int l, int r, int x) {
  if (l == r) return l;
  int mid = (l + r) / 2;
  int k = s[mid];
  if (x > k)
    return bfind_min(s, mid + 1, r, x);
  else
    return bfind_min(s, l, mid, x);
}
int bfind_max(long long* s, int l, int r, int x) {
  if (l == r) return l;
  int mid = (l + r + 1) / 2;
  int k = s[mid];
  if (x < k)
    return bfind_min(s, l, mid - 1, x);
  else
    return bfind_min(s, mid, r, x);
}
long long dfs(int rsn, int rew) {
  node& cur = net[rsn][rew];
  if (cur.mark) return 0;
  if (rsn == 0 || rsn == lsn_cnt || rew == 0 || rew == lew_cnt) return inf;
  long long area =
      (linesn[rsn] - linesn[rsn - 1]) * (lineew[rew] - lineew[rew - 1]);
  cur.mark = 1;
  if (cur.s) area += dfs(rsn, rew + 1);
  if (cur.n) area += dfs(rsn, rew - 1);
  if (cur.e) area += dfs(rsn + 1, rew);
  if (cur.w) area += dfs(rsn - 1, rew);
  return area > inf ? inf : area;
}
void find0() {
  sn0 = bfind_min(linesn, 0, lsn_cnt - 1, 0);
  ew0 = bfind_min(lineew, 0, lew_cnt - 1, 0);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    sn[i] = {c, a, b};
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    if (b > c) swap(b, c);
    ew[i] = {a, b, c};
  }
  sort(sn, sn + n);
  sort(ew, ew + m);
  linesn[lsn_cnt++] = sn[0].pos;
  lineew[lew_cnt++] = ew[0].pos;
  for (int i = 1; i < n; i++) {
    if (sn[i].pos != sn[i - 1].pos) linesn[lsn_cnt++] = sn[i].pos;
  }
  for (int i = 1; i < m; i++) {
    if (ew[i].pos != ew[i - 1].pos) lineew[lew_cnt++] = ew[i].pos;
  }
  int min_sn = linesn[0];
  int max_sn = linesn[lsn_cnt - 1];
  int min_ew = lineew[0];
  int max_ew = lineew[lew_cnt - 1];
  if (0 < min_sn || max_sn < 0 || 0 < min_ew || max_ew < 0) {
    cout << "INF";
    return 0;
  }
  int r = 0;
  for (int i = 0; i < n; i++) {
    if (sn[i].pos > linesn[r]) r++;
    if (sn[i].fr > max_ew || sn[i].to < min_ew) continue;
    int le = bfind_min(lineew, 0, lew_cnt - 1, sn[i].fr);
    int ri = bfind_max(lineew, 0, lew_cnt - 1, sn[i].to);
    for (int j = le + 1; j <= ri; j++) net[r][j].e = net[r + 1][j].w = 0;
  }
  r = 0;
  for (int i = 0; i < m; i++) {
    if (ew[i].pos > lineew[r]) r++;
    if (ew[i].fr > max_sn || ew[i].to < min_sn) continue;
    int le = bfind_min(linesn, 0, lsn_cnt - 1, ew[i].fr);
    int ri = bfind_max(linesn, 0, lsn_cnt - 1, ew[i].to);
    for (int j = le + 1; j <= ri; j++) net[j][r].s = net[j][r + 1].n = 0;
  }
  find0();
  long long ans = dfs(sn0, ew0);
  if (ans == inf)
    cout << "INF";
  else
    cout << ans;
}
