#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
template <typename T>
struct Compress {
  vector<T> xs;
  Compress() = default;
  Compress(const vector<T> &vs) { add(vs); }
  Compress(const initializer_list<vector<T>> &vs) {
    for (auto &p : vs) add(p);
  }
  void add(const vector<T> &vs) { copy(begin(vs), end(vs), back_inserter(xs)); }
  void add(const T &x) { xs.emplace_back(x); }
  void build() {
    sort(begin(xs), end(xs));
    xs.erase(unique(begin(xs), end(xs)), end(xs));
  }
  vector<int> get(const vector<T> &vs) const {
    vector<int> ret;
    transform(begin(vs), end(vs), back_inserter(ret), [&](const T &x) {
      return lower_bound(begin(xs), end(xs), x) - begin(xs);
    });
    return ret;
  }
  int get(const T &x) const {
    return lower_bound(begin(xs), end(xs), x) - begin(xs);
  }
  const T &operator[](int k) const { return xs[k]; }
};
ll G[3010][3010], Xw[3010][3010], Yw[3010][3010];
bool used[3010][3010];
ll A[1000], B[1000], C[1000], D[1000], E[1000], F[1000];
int main() {
  init();
  ll N, M;
  ll inf = (ll)(1e9 + 1);
  Compress<ll> cx({-inf, 0, inf}), cy({-inf, 0, inf});
  cin >> N >> M;
  for (ll i = 0; i < (N); i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    A[i] = a, B[i] = b, C[i] = c;
    cx.add(a), cx.add(b), cy.add(c);
  }
  for (ll i = 0; i < (M); i++) {
    ll d, e, f;
    cin >> d >> e >> f;
    D[i] = d, E[i] = e, F[i] = f;
    cx.add(d), cy.add(e), cy.add(f);
  }
  cx.build(), cy.build();
  ll xn = cx.xs.size(), yn = cy.xs.size();
  for (ll i = 0; i < (N); i++) {
    ll a = cx.get(A[i]), b = cx.get(B[i]), c = cy.get(C[i]);
    Xw[c][a + 1]++, Xw[c][b + 1]--;
  }
  for (ll i = 0; i < (yn); i++)
    for (ll j = (1); j < (xn); j++) Xw[i][j] += Xw[i][j - 1];
  for (ll i = 0; i < (M); i++) {
    ll d = cx.get(D[i]), e = cy.get(E[i]), f = cy.get(F[i]);
    Yw[d][e]++, Yw[d][f]--;
  }
  for (ll i = 0; i < (xn); i++)
    for (ll j = (1); j < (yn); j++) Yw[i][j] += Yw[i][j - 1];
  ll ans = 0;
  queue<pair<ll, ll>> q;
  q.emplace(cx.get(0), cy.get(0));
  used[0][0] = true;
  vl d = {1, -1};
  while (!q.empty()) {
    ll xi, yi;
    tie(xi, yi) = q.front(), q.pop();
    if (xi == 0 or xi == xn - 1 or yi == 0 or yi == yn - 1) {
      cout << "INF" << endl;
      return 0;
    }
    ans += (cx.xs[xi + 1] - cx.xs[xi]) * (cy.xs[yi + 1] - cy.xs[yi]);
    for (ll di = 0; di < (2); di++) {
      ll tyi = yi + d[di];
      if (used[xi][tyi] or Xw[max(yi, tyi)][xi]) continue;
      q.emplace(xi, tyi);
      used[xi][tyi] = true;
    }
    for (ll di = 0; di < (2); di++) {
      ll txi = xi + d[di];
      if (used[txi][yi] or Yw[min(xi, txi)][yi]) continue;
      q.emplace(txi, yi);
      used[txi][yi] = true;
    }
  }
  cout << ans << endl;
}
