#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

struct L {
  int a, b, c;
};

int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

signed main() {
  int N, M;
  cin >> N >> M;

  vector<L> xx, yy;
  map<int, int> mx, my;
  mx[0] = 0;
  my[0] = 0;

  REP(i, N){
    int a, b, c;
    cin >> a >> b >> c;
    mx[a] = 0;
    mx[b] = 0;
    my[c] = 0;
    xx.emplace_back(a, b, c);
  }
  REP(i, M){
    int a, b, c;
    cin >> a >> b >> c;
    mx[a] = 0;
    my[b] = 0;
    my[c] = 0;
    xx.emplace_back(a, b, c);
  }

  vector<int> 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);
  }

  int sx = mx[0]*2;
  int sy = my[0]*2;

  int H = xs.size()*2;
  int W = ys.size()*2;
  vector<vector<int>> d(H, vector<int>(W));
  d[sx][sy] = 1;

  REP(i, N){
    int a = mx[xx[i].a]*2;
    int b = mx[xx[i].b]*2;
    int c = my[xx[i].c]*2;
    FOR(j, a, b+1) d[j][c] = -1;
  }
  REP(i, M){
    int a = mx[yy[i].a]*2;
    int b = my[yy[i].b]*2;
    int c = my[yy[i].c]*2;
    FOR(j, b, c+1) d[a][j] = -1;
  }

  queue<pair<int, int>> q;
  q.emplace(sx, sy);

  while(!q.empty()){
    auto [x, y] = q.front(); q.pop();

    REP(i, 4){
      int nx = x+dx[i];
      int ny = y+dy[i];
      if(OUT(0, nx, H) || OUT(0, ny, W)) continue;
      if(d[nx][ny] != 0) continue;
      d[nx][ny] = 1;
      q.emplace(nx, ny);
    }
  }

  int ans = 0;
  REP(i, H) REP(j, W){
    if(d[i][j] != 1) continue;
    if(i%2 == 0 || j%2 == 0) continue;
    if(i == 0 || i == H-1 || j == 0 || j == W-1){
      cout << "INF" << "\n";
      return 0;
    }
    int ex = xs[i/2+1]-xs[i/2];
    int ey = ys[i/2+1]-ys[i/2];
    ans += ex*ey;
  }

  cout << ans << "\n";

  return 0;
}