#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

struct dsu {
  int cc;
  vector<int> p, sz;
  dsu(int n = 0) : cc(n), p(n, -1), sz(n, 1) {}
  int root(int v) const {
    while (p[v] != -1) v = p[v];
    return v;
  }
  bool unite(int u, int v) {
    u = root(u), v = root(v);
    if (u == v) return false;
    --cc;
    if (sz[u] < sz[v]) swap(u, v);
    p[v] = u;
    sz[u] += sz[v];
    return true;
  }
  bool same(int u, int v) const { return root(u) == root(v); }
  int size(int v) const { return sz[root(v)]; }
};

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<int> d(m), e(m), f(m);
  for (int j = 0; j < m; ++j) {
    cin >> d[j] >> e[j] >> f[j];
  }
  vector vx{-inf<int>, inf<int>};
  vector vy{-inf<int>, inf<int>};
  vx.insert(end(vx), begin(a), end(a));
  vx.insert(end(vx), begin(b), end(b));
  vy.insert(end(vy), begin(c), end(c));
  vx.insert(end(vx), begin(d), end(d));
  vy.insert(end(vy), begin(e), end(e));
  vy.insert(end(vy), begin(f), end(f));
  sort(begin(vx), end(vx));
  vx.erase(unique(begin(vx), end(vx)), end(vx));
  sort(begin(vy), end(vy));
  vy.erase(unique(begin(vy), end(vy)), end(vy));
  for (auto&& el : a) el = lower_bound(begin(vx), end(vx), el) - begin(vx);
  for (auto&& el : b) el = lower_bound(begin(vx), end(vx), el) - begin(vx);
  for (auto&& el : c) el = lower_bound(begin(vy), end(vy), el) - begin(vy);
  for (auto&& el : d) el = lower_bound(begin(vx), end(vx), el) - begin(vx);
  for (auto&& el : e) el = lower_bound(begin(vy), end(vy), el) - begin(vy);
  for (auto&& el : f) el = lower_bound(begin(vy), end(vy), el) - begin(vy);
  int h = size(vx) - 1;
  int w = size(vy) - 1;
  auto $ = [&](int i, int j) {
    return i * w + j;
  };
  vector ho(h + 1, vector<int>(w));
  vector ve(w + 1, vector<int>(h));
  for (int i = 0; i < n; ++i) {
    for (int x = a[i]; x < b[i]; ++x) {
      ve[c[i]][x] = 1;
    }
  }
  for (int j = 0; j < m; ++j) {
    for (int y = e[j]; y < f[j]; ++y) {
      ho[d[j]][y] = 1;
    }
  }
  dsu ds(h * w);
  for (int x = 0; x < h; ++x) {
    for (int y = 0; y < w; ++y) {
      if (x and not ho[x][y]) {
        ds.unite($(x, y), $(x - 1, y));
      }
      if (y and not ve[y][x]) {
        ds.unite($(x, y), $(x, y - 1));
      }
    }
  }
  int ox = lower_bound(begin(vx), end(vx), 0) - begin(vx);
  int oy = lower_bound(begin(vy), end(vy), 0) - begin(vy);
  if (ds.same(0, $(ox, oy))) {
    cout << "INF\n";
    exit(0);
  }
  long long res = 0;
  for (int x = 0; x < h; ++x) {
    for (int y = 0; y < w; ++y) {
      if (ds.same($(x, y), $(ox, oy))) {
        res += (long long)(vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
      }
    }
  }
  cout << res << '\n';
}
