#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> x;
  vector<ll> y;
  vector<vector<ll>> abc(N);
  vector<vector<ll>> def(M);
  bool ok = true;
  for (ll i = 0; i < N; ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    abc.at(i) = {a, b, c};
    x.push_back(a);
    x.push_back(b);
    y.push_back(c);
  }
  for (ll i = 0; i < M; ++i) {
    ll d, e, f;
    cin >> d >> e >> f;
    def.at(i) = {d, e, f};
    x.push_back(d);
    y.push_back(e);
    y.push_back(f);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  x.erase(unique(x.begin(), x.end()) , x.end());
  y.erase( unique( y.begin(), y.end()) , y.end() );
  vector<vector<ll>> fixed_abc(N), fixed_def(M);
  for (ll i = 0; i < N; ++i) {
    vector<ll> check = abc.at(i);
    fixed_abc.at(i) = {lower_bound(x.begin(), x.end(), check.at(0)) - x.begin(), lower_bound(x.begin(), x.end(), check.at(1)) - x.begin(), lower_bound(y.begin(), y.end(), check.at(2)) - y.begin()};
  }
  for (ll i = 0; i < M; ++i) {
    vector<ll> check = def.at(i);
    fixed_def.at(i) = {lower_bound(x.begin(), x.end(), check.at(0)) - x.begin(), lower_bound(y.begin(), y.end(), check.at(1)) - y.begin(), lower_bound(y.begin(), y.end(), check.at(2)) - y.begin()};
  }
  vector<vector<ll>> field(y.size() * 2, vector<ll>(x.size() * 2, -1));
  for (ll i = 1; i < y.size() * 2 - 1; ++i) {
    for (ll j = 1; j < x.size() * 2 - 1; ++j) {
      field.at(i).at(j) = 0;
    }
  }
  for (ll i = 0; i < N; ++i) {
    vector<ll> check = fixed_abc.at(i);
    for (ll x_len = check.at(0) * 2; x_len <= check.at(1) * 2; ++x_len) {
      field.at(check.at(2) * 2).at(x_len) = 1;
    }
  }
  for (ll i = 0; i < M; ++i) {
    vector<ll> check = fixed_def.at(i);
    for (ll y_len = check.at(1) * 2; y_len <= check.at(2) * 2; ++y_len) {
      field.at(y_len).at(check.at(0) * 2) = 1;
    }
  }
  // for (ll i = 0; i < y.size() * 2; ++i) {
  //   for (ll j = 0; j < x.size() * 2; ++j) {
  //     cout << field.at(i).at(j);
  //   }
  //   cout << "\n";
  // }
  pll start = {(lower_bound(x.begin(), x.end(), 0) - x.begin()) * 2 - 1, (lower_bound(y.begin(), y.end(), 0) - y.begin()) * 2 - 1};
  if (start.first < 0 || start.second < 0) {
    cout << "INF" << "\n";
    return 0;
  }
  queue<pll> q;
  q.push(start);
  field.at(start.second).at(start.first) = 2;
  vector<vector<ll>> move = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  while (!q.empty()) {
    pll now = q.front();
    q.pop();
    for (ll i = 0; i < 4; ++i) {
      pll next = {now.first + move.at(i).at(0), now.second + move.at(i).at(1)};
      if (field.at(next.second).at(next.first) == -1) {
        cout << "INF" << "\n";
        return 0;
      }
      if (field.at(next.second).at(next.first) == 0) {
        field.at(next.second).at(next.first) = 2;
        q.push({next.first, next.second});
      }
    }
  }

  ll ans = 0;
  for (ll i = 0; i < y.size(); ++i) {
    for (ll j = 0; j < x.size(); ++j) {
      if (field.at(i * 2 + 1).at(j * 2 + 1) == 2) {
        ll x_wid = x.at(j + 1) - x.at(j), y_wid = y.at(i + 1) - y.at(i);
        ans += (x_wid * y_wid);
      }
    }
  }
  cout << ans << "\n";
  // for (ll i = 0; i < y.size() * 2; ++i) {
  //   for (ll j = 0; j < x.size() * 2; ++j) {
  //     cout << field.at(i).at(j);
  //   }
  //   cout << "\n";
  // }
}


Measured memory_bytes: 284912