#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
constexpr long long mod = 1e9 + 7;
constexpr long long Mod = 998244353;
constexpr long long MXN = 500000 + 100;
constexpr ld EPS = 1e-10;
constexpr ll inf = 3 * 1e18;
constexpr long long Inf = 15 * 1e8;
const vector<long long> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll read() {
  ll u, k = scanf("%lld", &u);
  return u;
}
string reads() {
  string s;
  cin >> s;
  return s;
}
pair<long long, long long> readh(bool g = 0) {
  pair<long long, long long> u;
  long long k = scanf("%lld %lld", &u.first, &u.second);
  if (g) u.first--, u.second--;
  return u;
}
bool inarea(pair<long long, long long> t, long long h, long long w) {
  return 0 <= t.first && t.first < h && 0 <= t.second && t.second < w;
}
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p = mod) {
  ll res = 1;
  x %= p;
  while (n > 0) {
    if (n & 1) res = res * x % p;
    x = x * x % p;
    n >>= 1;
  }
  return res;
}
ll bitcount(ll x) {
  long long sum = 0;
  for (long long i = 0; i < 60; i++)
    if ((1ll << i) & x) sum++;
  return sum;
}
constexpr long long fn_ = 5000005;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll m) {
  if (!fact_[0]) {
    fact_[0] = 1;
    comp_[0] = 1;
    for (long long i = 1; i < fn_; i++) fact_[i] = fact_[i - 1] * i % m;
    comp_[fn_ - 1] = mod_pow(fact_[fn_ - 1], m - 2, m);
    for (long long i = fn_ - 2; i > 0; i--)
      comp_[i] = comp_[i + 1] * (i + 1) % m;
  }
  if (x < y) return 0;
  return fact_[x] * comp_[x - y] % m * comp_[y] % m;
}
short c[5000][5000];
bool d[5000][5000];
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> x, y;
  vector<pair<long long, pair<long long, long long>>> a, b;
  x.emplace_back(0);
  y.emplace_back(0);
  x.emplace_back(-1e10);
  y.emplace_back(-1e10);
  x.emplace_back(1e10);
  y.emplace_back(1e10);
  for (long long i = (0); i < ((n)); i++) {
    long long u, v, r;
    cin >> u >> v >> r;
    a.emplace_back(make_pair(u, make_pair(v, r)));
    y.emplace_back(r);
    x.emplace_back(u);
    x.emplace_back(v);
  }
  for (long long i = (0); i < ((m)); i++) {
    long long u, v, r;
    cin >> u >> v >> r;
    b.emplace_back(make_pair(u, make_pair(v, r)));
    x.emplace_back(u);
    y.emplace_back(v);
    y.emplace_back(r);
  }
  sort(((x)).begin(), ((x)).end());
  (x).erase(unique(((x)).begin(), ((x)).end()), (x).end());
  sort(((y)).begin(), ((y)).end());
  (y).erase(unique(((y)).begin(), ((y)).end()), (y).end());
  for (long long i = (0); i < ((n)); i++) {
    long long t = lower_bound((x).begin(), (x).end(), (a[i].second.first)) -
                  x.begin(),
              r = lower_bound((y).begin(), (y).end(), (a[i].second.second)) -
                  y.begin();
    for (long long j =
             (lower_bound((x).begin(), (x).end(), (a[i].first)) - x.begin());
         j < (t); j++) {
      c[j][r] = 1;
    }
  }
  for (long long i = (0); i < ((m)); i++) {
    long long t = lower_bound((y).begin(), (y).end(), (b[i].second.second)) -
                  y.begin(),
              r = lower_bound((x).begin(), (x).end(), (b[i].first)) - x.begin();
    for (long long j =
             (lower_bound((y).begin(), (y).end(), (b[i].second.first)) -
              y.begin());
         j < (t); j++) {
      c[r][j] |= 2;
    }
  }
  queue<pair<long long, long long>> q;
  q.push(pair<long long, long long>{
      lower_bound((x).begin(), (x).end(), (0)) - x.begin(),
      lower_bound((y).begin(), (y).end(), (0)) - y.begin()});
  d[lower_bound((x).begin(), (x).end(), (0)) - x.begin()]
   [lower_bound((y).begin(), (y).end(), (0)) - y.begin()] = 1;
  while (!q.empty()) {
    pair<long long, long long> t = q.front();
    q.pop();
    if (x[t.first] == -1e10 || x[t.first + 1] == 1e10 || y[t.second] == -1e10 ||
        y[t.second + 1] == 1e10) {
      cout << "INF\n";
      return 0;
    }
    for (long long z = (0); z < ((4)); z++) {
      pair<long long, long long> k = t;
      k.first += dx[z], k.second += dy[z];
      if (z == 0 && c[t.first][t.second] & 2) continue;
      if (z == 1 && c[t.first + 1][t.second] & 2) continue;
      if (z == 2 && c[t.first][t.second] & 1) continue;
      if (z == 3 && c[t.first][t.second + 1] & 1) continue;
      if (!d[k.first][k.second]) {
        d[k.first][k.second] = 1;
        q.push(pair<long long, long long>{k.first, k.second});
      }
    }
  }
  long long ans = 0;
  for (long long i = (0); i < ((x.size() - 1)); i++)
    for (long long j = (0); j < ((y.size() - 1)); j++) {
      if (d[i][j]) {
        ans += (x[i + 1] - x[i]) * (y[i + 1] - y[i]);
      }
    }
  cout << ans << endl;
}
