#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vll = vector<ll>;
using vvll = vector<vll>;
pii ch[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
  int n, m;
  cin >> n >> m;
  vi a(n + 1), b(n + 1), c(n + 1), d(m + 1), e(m + 1), f(m + 1);
  vll x, y;
  const int MX = 1e9;
  x.push_back(-(MX + 5));
  x.push_back(MX + 5);
  y.push_back(-(MX + 5));
  y.push_back(MX + 5);
  for (int i = 1; i <= (n); i++) {
    cin >> a[i] >> b[i] >> c[i];
    x.push_back(a[i]);
    x.push_back(b[i]);
    y.push_back(c[i]);
  }
  for (int i = 1; i <= (m); i++) {
    cin >> d[i] >> e[i] >> f[i];
    x.push_back(d[i]);
    y.push_back(e[i]);
    y.push_back(f[i]);
  }
  sort(begin(x), end(x));
  sort(begin(y), end(y));
  auto xt = unique(begin(x), end(x));
  auto yt = unique(begin(y), end(y));
  x.erase(xt, x.end());
  y.erase(yt, y.end());
  int sx = lower_bound(begin(x), end(x), 0) - x.begin(),
      sy = lower_bound(begin(y), end(y), 0) - y.begin();
  int xs = x.size() - 1, ys = y.size() - 1;
  using vb = vector<bool>;
  using vvb = vector<vb>;
  vvb vis(ys + 1, vb(xs + 1));
  vector<vvb> can(4, vvb(ys + 1, vb(xs + 1, 1)));
  for (int i = 1; i <= (n); i++) {
    int al = lower_bound(begin(x), end(x), a[i]) - x.begin();
    int bl = lower_bound(begin(x), end(x), b[i]) - x.begin();
    int cl = lower_bound(begin(y), end(y), c[i]) - y.begin();
    for (int j = al; j <= (bl - 1); j++) can[2][j][cl - 1] = can[3][j][cl] = 0;
  }
  for (int i = 1; i <= (m); i++) {
    int dl = lower_bound(begin(x), end(x), d[i]) - x.begin();
    int el = lower_bound(begin(y), end(y), e[i]) - y.begin();
    int fl = lower_bound(begin(y), end(y), f[i]) - y.begin();
    for (int j = el; j <= (fl - 1); j++) can[0][dl - 1][j] = can[1][dl][j] = 0;
  }
  queue<pii> q;
  q.push({sx, sy});
  vis[sx][sy] = 1;
  while (!q.empty()) {
    pii u = q.front();
    q.pop();
    for (int i = 0; i <= (3); i++) {
      pii v = {u.first + ch[i].first, u.second + ch[i].second};
      if (!can[i][u.first][u.second] || v.first < 1 || v.first > ys ||
          v.second < 1 || v.second > xs)
        continue;
      if (!vis[v.first][v.second]) {
        vis[v.first][v.second] = 1;
        q.push(v);
      }
    }
  }
  bool inf = 0;
  for (int i = 1; i <= (ys); i++)
    if (vis[i][1] || vis[i][xs]) inf = 1;
  for (int i = 1; i <= (xs); i++)
    if (vis[1][i] || vis[ys][i]) inf = 1;
  if (inf) return cout << "INF\n", 0;
  ll ans = 0;
  for (int i = 1; i <= (ys); i++)
    for (int j = 1; j <= (xs); j++) {
      if (vis[i][j]) ans += (y[i] - y[i - 1]) * (x[j] - x[j - 1]);
    }
  cout << ans << endl;
}
