// 2020-07-26 23:46:17
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

struct L {
  ll s, t, u;
  L(ll s_, ll t_, ll u_) : s(s_), t(t_), u(u_) {}
};

void answer() {
  int n, m;
  cin >> n >> m;
  vector<L> lx, ly;
  map<ll, int> mx, my;
  mx[0] = 0;
  my[0] = 0;
  rep(i, n) {
    int s, t, u;
    cin >> s >> t >> u;
    lx.emplace_back(L(s, t, u));
    mx[s] = 0;
    mx[t] = 0;
    my[u] = 0;
  }
  rep(i, m) {
    int s, t, u;
    cin >> u >> s >> t;
    ly.emplace_back(L(s, t, u));
    my[s] = 0;
    my[t] = 0;
    mx[u] = 0;
  }
  vector<ll> xs, ys;
  for(auto& p : mx) {
    p.second = xs.size();
    xs.emplace_back(p.first);
  }
  for(auto& p : my) {
    p.second = ys.size();
    ys.emplace_back(p.first);
  }
  vector<vector<int> > G(xs.size() * 2, vector<int>(ys.size() * 2, 0));
  for(const auto& l : lx) {
    int yi = my[l.u] * 2;
    REPC(xi, mx[l.s] * 2, mx[l.t] * 2) {
      G[xi][yi] = -1;
    }
  }
  for(const auto& l : ly) {
    int xi = mx[l.u] * 2;
    REPC(yi, my[l.s] * 2, my[l.t] * 2) {
      G[xi][yi] = -1;
    }
  }
  queue<P> que;
  {
    int s = mx[0] * 2 + 1;
    int t = my[0] * 2 + 1;
    que.emplace(P(s, t));
  }
  int xr = xs.size() * 2, yr = ys.size() * 2;
  {
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};
    while(!que.empty()) {
      int x, y;
      tie(x, y) = que.front(); que.pop();
      if(x == 0 || x == xr-1 || y == 0 || y == yr-1) {
        cout << "INF" << '\n';
        return;
      }
      if(G[x][y] == 1) continue;
      G[x][y] = 1;
      rep(di, 4) {
        int nx = x + dx[di], ny = y + dy[di];
        if(0 <= nx && nx < xr && 0 <= ny && ny < yr && G[nx][ny] == 0) {
          que.emplace(P(nx, ny));
        }
      }
    }
  }
  ll ans = 0;
  rep(x, xr-1) rep(y, yr-1) {
    if(G[x][y] == 1 && x % 2 && y % 2) {
      ans += (xs[(x+1)/2] - xs[x/2]) * (ys[(y+1)/2] - ys[y/2]);
    }
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}