#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  ll n, m;
  cin>>n>>m;

  ll a, b, c;
  set<ll> ys, xs;
  vector<pair<ll, pair<ll, ll>>> vertical, horizontal;
  for (ll i=0; i<n; i++) {
    cin>>a>>b>>c;
    ys.insert(c);
    horizontal.push_back({c, {a, b}});
  }
  ys.insert(0);
  ys.insert((*ys.begin())-1);
  ys.insert(1e9+1);
  sort(horizontal.begin(), horizontal.end());

  ll d, e, f;
  for (ll i=0; i<m; i++) {
    cin>>d>>e>>f;
    xs.insert(d);
    vertical.push_back({d, {e, f}});
  }
  xs.insert(0);
  xs.insert((*xs.begin())-1);
  xs.insert(1e9+1);
  sort(vertical.begin(), vertical.end());

  vector<ll> xlines, ylines;
  for (auto p = xs.begin(); p != xs.end(); p++)
    xlines.push_back(*p);
  for (auto p = ys.begin(); p != ys.end(); p++)
    ylines.push_back(*p);

  bool connected[1005][1005][4] = {true};
  for (int i=0; i<1005; i++)
    for (int j=0; j<1005; j++)
      for (int k=0; k<4; k++)
        connected[i][j][k] = true;

  int up = 0, down = 1, left = 2, right = 3;
  int diff[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};

  ll index = 0;
  for (ll i=0; i<xlines.size()-1; i++) {
    while (index < vertical.size() && vertical[index].first < xlines[i+1]) index++;

    if (index == vertical.size()) break;
    if (vertical[index].first > xlines[i+1]) continue;

    for (ll j=0; j<ylines.size()-1; j++) {
      while (index < vertical.size() 
          && vertical[index].first == xlines[i+1]
          && vertical[index].second.second <= ylines[j]) 
        index++;
      if (index == vertical.size() || vertical[index].first > xlines[i+1]) break;
      if (vertical[index].second.first <= ylines[j] && vertical[index].second.second >= ylines[j+1]) {
        connected[i][j][right] = false;
        connected[i+1][j][left] = false;
      }
    }
  }

  index = 0;
  for (ll j=0; j<ylines.size()-1; j++) {
    while (index < horizontal.size() && horizontal[index].first < ylines[j+1]) index++;
    
    if (index == horizontal.size()) break;
    if (horizontal[index].first > ylines[j+1]) continue;

    for (ll i=0; i<xlines.size()-1; i++) {
      while (index < horizontal.size() 
          && horizontal[index].first == ylines[j+1]
          && horizontal[index].second.second <= xlines[i]) index++;

      if (index == horizontal.size() || horizontal[index].first > ylines[j+1]) break;
      if (horizontal[index].second.first <= xlines[i] && horizontal[index].second.second >= xlines[i+1]) {
        connected[i][j][up] = false;
        connected[i][j+1][down] = false;
      }
    }
  }

  ll start_x = -1, start_y = -1;
  for (ll i=0; i<xlines.size(); i++)
    if (xlines[i] == 0) {
      start_x = i;
      break;
    }
  for (ll i=0; i<ylines.size(); i++)
    if (ylines[i] == 0) {
      start_y = i;
      break;
    }

  bool vis[1005][1005] = {false};
  queue<pair<int, int>> current;
  bool inf = false;
  ll ans = 0;
  vis[start_x][start_y] = true;
  current.push({start_x, start_y});

  while (current.size() > 0) {
    auto p = current.front();
    current.pop();

    //printf("(%d, %d)\n", p.first, p.second);
    if (p.first == 0 || p.first >= xlines.size()-2) {
      inf = true;
      break;
    }

    if (p.second == 0 || p.second >= ylines.size()-2) {
      inf = true;
      break;
    }

    ans += (xlines[p.first+1] - xlines[p.first]) * (ylines[p.second+1] - ylines[p.second]);

    for (int k = 0; k<4; k++) {
      int x = p.first + diff[k][0];
      int y = p.second + diff[k][1];
      
      if (connected[p.first][p.second][k] && !vis[x][y]) {
        vis[x][y] = true;
        current.push({x, y});
      }
    }
  }

  if (inf)
    cout<<"INF"<<endl;
  else
    cout<<ans<<endl;
}

int 
main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}




Measured memory_bytes: 8740