#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, m;
  cin >> n >> m;

  vector<pair<pii, int>> ver, hor;
  vector<int> xs, ys;
  xs.pb(-1.1e9); xs.pb(0); xs.pb(1.1e9);
  ys.pb(-1.1e9); ys.pb(0); ys.pb(1.1e9);

  rep(i,0,n) {
    int a, b, c;
    cin >> a >> b >> c;
    ver.eb(mp(a,b), c);
    ys.pb(a);
    ys.pb(b);
    xs.pb(c);
  }

  rep(i,0,m) {
    int a, b, c;
    cin >> a >> b >> c;
    hor.eb(mp(b,c), a);
    xs.pb(b);
    xs.pb(c);
    ys.pb(a);
  }

  auto xpos = [&](int x) -> int {
    return lower_bound(all(xs), x) - xs.begin();
  };

  auto ypos = [&](int y) -> int {
    return lower_bound(all(ys), y) - ys.begin();
  };

  sort(all(xs));
  sort(all(ys));
  xs.resize(unique(all(xs))-xs.begin());
  ys.resize(unique(all(ys))-ys.begin());

  n = sz(ys);
  m = sz(xs);

  vvi mat(n, vi(m));

  int di[4] = {0, -1, 0, 1};
  int dj[4] = {1, 0, -1, 0};

  rep(i,0,sz(ver)) {
    auto [y1, y2] = ver[i].fst;
    int x = ver[i].snd;
    y1 = ypos(y1);
    y2 = ypos(y2);
    x = xpos(x);
    rep(i,y1,y2) {
      mat[i][x] |= 1<<2;
      mat[i][x-1] |= 1<<0;
    }
  }

  rep(i,0,sz(hor)) {
    auto [x1, x2] = hor[i].fst;
    int y = hor[i].snd;
    x1 = xpos(x1);
    x2 = xpos(x2);
    y = ypos(y);
    rep(i,x1,x2) {
      mat[y][i] |= 1<<1;
      mat[y-1][i] |= 1<<3;
    }
  }

#define in(i,j) ((i) >= 0 and (i) < n and (j) >= 0 and (j) < m)

  queue<pii> q;
  vector<bitset<4123>> vis(n);
  int x0 = xpos(0), y0 = ypos(0);
  q.emplace(y0, x0); q.emplace(y0-1, x0); q.emplace(y0, x0-1); q.emplace(y0-1, x0-1);
  vis[y0][x0] = 1; vis[y0-1][x0] = 1; vis[y0][x0-1] = 1; vis[y0-1][x0-1] = 1;

  while (not q.empty()) {
    auto [i, j] = q.front(); q.pop();
    rep(k,0,4) {
      if (mat[i][j]&(1<<k)) continue;
      int ni = i+di[k], nj = j+dj[k];
      if (not in(ni,nj)) continue;
      if (vis[ni][nj]) continue;
      vis[ni][nj] = 1;
      q.emplace(ni, nj);
    }
  }

  rep(i,0,n) {
    if (vis[i][0] or vis[i][m-1]) {
      cout << "INF\n";
      return 0;
    }
  }

  rep(i,0,m) {
    if (vis[0][i] or vis[n-1][i]) {
      cout << "INF\n";
      return 0;
    }
  }

  ll ans = 0;
  rep(i,0,n) rep(j,0,m) if (vis[i][j]) {
    ans += ll(xs[j+1] - xs[j]) * ll(ys[i+1] - ys[i]);
  }
  cout << ans << '\n';

}