#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll N, M;
map<ll, vector<pair<ll, ll>>> mapping[2];
vector<ll> key[2];
bool D[2048][2048] = {};
ll conv(const vector<ll> &axis, ll fld) {
  auto it = lower_bound(axis.begin(), axis.end(), fld);
  ll dif = it - axis.begin();
  if (it == axis.end()) {
    return axis.size() * 2;
  } else if (*it == fld) {
    return dif * 2 + 1;
  } else {
    return dif * 2;
  }
}
ll is_out(const vector<ll> &axis, ll fld) {
  if (fld < axis[0] || fld > axis[axis.size() - 1]) {
    return true;
  }
  return false;
}
ll area(ll x, ll y) {
  if (x % 2 == 1 || y % 2 == 1) {
    return 0;
  }
  x /= 2;
  y /= 2;
  return (key[0][x] - key[0][x - 1]) * (key[1][y] - key[1][y - 1]);
}
int main() {
  cin >> N >> M;
  ;
  for (ll i = 0; i < (N); i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    mapping[0][c].emplace_back(make_pair(a, b));
  }
  for (ll j = 0; j < (M); j++) {
    ll d, e, f;
    cin >> d >> e >> f;
    mapping[1][d].emplace_back(make_pair(e, f));
  }
  for (ll i = 0; i < (2); i++) {
    for (auto &kv : mapping[i]) {
      key[i].push_back(kv.first);
    }
    sort(key[i].begin(), key[i].end());
  }
  for (ll i = 0; i < (2); i++) {
    for (auto &kv : mapping[i]) {
      ll y = conv(key[i], kv.first);
      for (auto &p : kv.second) {
        ll x0 = conv(key[1 - i], p.first), x1 = conv(key[1 - i], p.second);
        for (ll x = x0; x <= x1; x++) {
          if (i == 0) {
            D[x][y] = true;
          } else {
            D[y][x] = true;
          }
        }
      }
    }
  }
  queue<pair<ll, ll>> q;
  ll x0 = conv(key[0], 0);
  ll y0 = conv(key[1], 0);
  q.push(make_pair(x0, y0));
  ll sum = 0;
  ll sizeX = key[0].size() * 2;
  ll sizeY = key[1].size() * 2;
  while (!q.empty()) {
    ll x = q.front().first, y = q.front().second;
    q.pop();
    if (!(0 < x && x < sizeX && 0 < y && y < sizeY)) {
      cout << "INF" << endl;
      return 0;
    }
    if (D[x][y]) continue;
    D[x][y] = true;
    sum += area(x, y);
    const ll dx[] = {1, -1, 0, 0};
    const ll dy[] = {0, 0, 1, -1};
    for (ll i = 0; i < (4); i++) {
      q.push(make_pair(x + dx[i], y + dy[i]));
    }
  }
  cout << sum << endl;
  return 0;
}
