#include <bits/stdc++.h>
using namespace std;
long long w[2002], h[2002], a[2002][2002] = {}, ans = 0;
int n, m, w1 = 0, h1 = 0;
struct seg {
  int pos;
  int fr;
  int to;
  bool operator<(const seg& s) const {
    return (pos < s.pos || (pos == s.pos && fr < s.fr));
  }
} wseg[1001], hseg[1001];
void cut(seg* segs, long long* t1, long long* t2, int t2_n, int k, int sw) {
  int r = 0;
  for (int i = 0; i < k; i++) {
    if (segs[i].pos != t1[r]) r += 2;
    if (i < n - 1)
      if (segs[i].pos == segs[i + 1].pos && segs[i].to >= segs[i + 1].fr) {
        segs[i + 1].fr = segs[i].fr;
        segs[i + 1].to = max(segs[i].to, segs[i + 1].to);
        continue;
      }
    for (int j = lower_bound(t2, t2 + t2_n, segs[i].fr) - t2;
         j < t2_n && (j == t2_n - 1 ? 1 : t2[j + 1] <= segs[i].to); j++) {
      if (sw)
        a[r][j] = 1;
      else
        a[j][r] = 1;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> wseg[i].fr >> wseg[i].to >> wseg[i].pos;
  }
  for (int i = 0; i < m; i++) {
    cin >> hseg[i].pos >> hseg[i].fr >> hseg[i].to;
  }
  sort(wseg, wseg + n);
  sort(hseg, hseg + m);
  int pr = wseg[0].pos;
  w[w1++] = pr;
  for (int i = 1; i < n; i++) {
    if (wseg[i].pos != pr) {
      w[w1++] = pr;
      pr = wseg[i].pos;
      w[w1++] = pr;
    }
  }
  pr = hseg[0].pos;
  h[h1++] = pr;
  for (int i = 1; i < m; i++) {
    if (hseg[i].pos != pr) {
      h[h1++] = pr;
      pr = hseg[i].pos;
      h[h1++] = pr;
    }
  }
  cut(wseg, w, h, h1, n, 1);
  cut(hseg, h, w, w1, m, 0);
  queue<pair<int, int>> que;
  int x0 = upper_bound(w, w + w1, 0) - w;
  int y0 = upper_bound(h, h + h1, 0) - h;
  if (!x0 || !y0) {
    cout << "INF";
    return 0;
  }
  que.push({x0 - 1, y0 - 1});
  while (!que.empty()) {
    auto t = que.front();
    que.pop();
    int x = t.first;
    int y = t.second;
    if (a[x][y]) continue;
    if (x == 0 || y == 0 || x == w1 - 1 || y == h1 - 1) {
      cout << "INF";
      return 0;
    }
    ans += (w[x + 1] - w[x]) * (h[y + 1] - h[y]);
    a[x][y] = 1;
    que.push({x + 1, y});
    que.push({x - 1, y});
    que.push({x, y + 1});
    que.push({x, y - 1});
  }
  cout << ans;
}
