#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T1, typename T2>
bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
using namespace std;
using ll = long long;
struct Z {
  ll y;
  ll x;
  ll depth;
};
ll N, M, y, x, depth, oo = 4e18, xs, ys, ans = 0;
ll ysize, xsize;
vector<ll> y_vec = {1, 0, -1, 0};
vector<ll> x_vec = {0, 1, 0, -1};
vector<vector<ll>> A;
vector<ll> var_s(0, 0), hor_s(0, 0);
queue<Z> Q;
void bfs() {
  while (!Q.empty()) {
    Z now = Q.front();
    Q.pop();
    y = now.y, x = now.x, depth = now.depth;
    if (y == 1 || y == ysize - 2 || x == 1 || x == xsize - 1) {
      ans = oo;
      return;
    }
    for (ll i = 0; i < 4; i++) {
      Z next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (A[next.y][next.x] == -1) continue;
      if ((next.y % 2) && (next.x % 2)) {
        ll y1 = next.y / 2;
        ll x1 = next.x / 2;
        ans += (var_s[y1] - var_s[y1 - 1]) * (hor_s[x1] - hor_s[x1 - 1]);
      }
      A[next.y][next.x] = -1;
      Q.push(next);
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> N >> M;
  map<ll, ll> vm, hm;
  vector<pair<ll, ll>> var(N + 1, {0, 0}), hor(M + 1, {0, 0});
  vector<ll> varc(N + 1, 0), hord(M + 1, 0);
  for (ll i = 0; i < N; ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (vm[a] == 0) var_s.push_back(a);
    if (vm[b] == 0) var_s.push_back(b);
    vm[a]++;
    vm[b]++;
    var[i] = {a, b};
    varc[i] = c;
    if (hm[c] == 0) hor_s.push_back(c);
    hm[c]++;
  }
  for (ll i = 0; i < M; ++i) {
    ll d, e, f;
    cin >> d >> e >> f;
    if (hm[e] == 0) hor_s.push_back(e);
    if (hm[f] == 0) hor_s.push_back(f);
    hm[e]++;
    hm[f]++;
    hor[i] = {e, f};
    hord[i] = d;
    if (vm[d] == 0) var_s.push_back(d);
    vm[d]++;
  }
  ysize = var_s.size() * 2 + 3;
  xsize = hor_s.size() * 2 + 3;
  A.assign(ysize, vector<ll>(xsize, 0));
  for (ll i = 0; i < ysize; i++) {
    A[i][0] = -1;
    A[i][xsize - 1] = -1;
  }
  for (ll j = 0; j < xsize; j++) {
    A[0][j] = -1;
    A[ysize - 1][j] = -1;
  }
  vector<ll> yi(6010, 0);
  vector<ll> xi(6010, 0);
  sort(begin(var_s), end(var_s));
  sort(begin(hor_s), end(hor_s));
  ll index = 0, vsz = var_s.size(), hsz = hor_s.size();
  for (ll i = 0; i < vsz; ++i) yi[i] = var_s[i];
  for (ll i = 0; i < hsz; ++i) xi[i] = hor_s[i];
  for (ll i = 0; i < N; ++i) {
    ll y1 = var[i].first;
    ll y2 = var[i].second;
    ll c = varc[i];
    ll yi1 = lower_bound(begin(var_s), end(var_s), y1) - var_s.begin();
    ll yi2 = lower_bound(begin(var_s), end(var_s), y2) - var_s.begin();
    ll ci = lower_bound(begin(hor_s), end(hor_s), c) - hor_s.begin();
    yi1 = (yi1 + 1) * 2;
    yi2 = (yi2 + 1) * 2;
    ci = (ci + 1) * 2;
    for (ll j = yi1; j <= yi2; j++) A[j][ci] = -1;
  }
  for (ll i = 0; i < M; ++i) {
    ll x1 = hor[i].first;
    ll x2 = hor[i].second;
    ll d = hord[i];
    ll xi1 = lower_bound(begin(hor_s), end(hor_s), x1) - hor_s.begin();
    ll xi2 = lower_bound(begin(hor_s), end(hor_s), x2) - hor_s.begin();
    ll di = lower_bound(begin(var_s), end(var_s), d) - var_s.begin();
    xi1 = (xi1 + 1) * 2;
    xi2 = (xi2 + 1) * 2;
    di = (di + 1) * 2;
    for (ll j = xi1; j <= xi2; j++) A[di][j] = -1;
  }
  ll ysi = lower_bound(begin(var_s), end(var_s), 0) - var_s.begin();
  ll xsi = lower_bound(begin(hor_s), end(hor_s), 0) - hor_s.begin();
  ys = (ysi + 1) * 2;
  xs = (xsi + 1) * 2;
  A[ys][xs] = -1;
  Z start = {ys, xs, 0};
  Q.emplace(start);
  bfs();
  if (ans == oo)
    cout << "INF" << endl;
  else
    cout << ans << endl;
}
