#include <bits/stdc++.h>
#define INF 2e9
using namespace std;

map<long long, array<int,3010>> hor_dic;
map<long long, array<int,3010>> ver_dic;
map<long long, int> xdic;
map<long long, int> ydic;
map<int, long long> gyaku_xdic;
map<int, long long> gyaku_ydic;
int dx[4]={ 0, 1,  0, -1};
int dy[4]={ 1, 0, -1,  0};
array<array<int,3000>,3000> d;
long long area = 0;
array<array<long long,2>,10000000> q;
long long q_len;

bool is_connected(long long x,long long y,int dx,int dy){
  if (dx == 0){
    if(dy > 0){
      if (hor_dic[y+1][x]){
        return false;
      }
      return true;
    }else{
      if (hor_dic[y][x]){
        return false;
      }
      return true;
    }  
  }else{
    if (dx > 0){
      if (ver_dic[x+1][y]){
        return false;
      }
      return true;
    }else{
      if (ver_dic[x][y]){
        return false;
      }
      return true;
    }
  }
}

long long calc_area(long long x,long long y){
  long long X;
  long long Y;
  X = gyaku_xdic[x+1] - gyaku_xdic[x];
  Y = gyaku_ydic[y+1] - gyaku_ydic[y];
  return X*Y;
}

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

  array<array<long long,3>,1000> hor;
  array<array<long long,3>,1000> ver;
  long long xtic[1+N*2+M];
  long long ytic[1+N+M*2];
  xtic[0] = 0;
  ytic[0] = 0;
 
  for(int i = 0; i < N; i++){
    int a,b,c; cin >> a >> b >> c;
    hor[i][0] = c;
    hor[i][1] = a;
    hor[i][2] = b;
    xtic[i*2+1] = a;
    xtic[i*2+2] = b;
    ytic[i+1] = c;
  }
  for(int i = 0; i < M; i++){
    int d,e,f; cin >> d >> e >> f;
    ver[i][0] = d;
    ver[i][1] = e;
    ver[i][2] = f;
    xtic[N*2+i+1] = d;
    ytic[N+i*2+1] = e;
    ytic[N+i*2+2] = f;
  }
  
  sort(xtic,xtic+(1+N*2+M));
  sort(ytic,ytic+(1+N+M*2));
  
  long long x_tic[1+N*2+M];
  long long y_tic[1+N+M*2];
  int count = 0;
  long long prev = -INF;
  for(int i = 0; i < (1+N*2+M); i++){
    if (prev != xtic[i]){
      x_tic[count] = xtic[i];
      count += 1;
      prev = xtic[i];
    }
  }
  int len_x_tic = count;
  count = 0;
  prev = -INF;
  for(int i = 0; i < (1+N+M*2); i++){
    if (prev != ytic[i]){
      y_tic[count] = ytic[i];
      count += 1;
      prev = ytic[i];
    }
  }
  int len_y_tic = count;
  

  for(int i = 0; i < len_x_tic; i++){
    xdic[x_tic[i]] = i+1;
    gyaku_xdic[i+1] = x_tic[i];
  }
  for(int i = 0; i < len_y_tic; i++){
    ydic[y_tic[i]] = i+1;
    gyaku_ydic[i+1] = y_tic[i];
  }
  
  sort(&hor[0], &hor[N], [](auto& x, auto& y){return x[0] < y[0];});
  sort(&ver[0], &ver[M], [](auto& x, auto& y){return x[0] < y[0];});
  
  for(int i = 0; i < N; i++){
    long long c = hor[i][0];
    long long a = hor[i][1];
    long long b = hor[i][2];
    c = ydic[c];
    a = xdic[a];
    b = xdic[b];
    for(int j = a; j < b; j++){
      hor_dic[c][j] = 1;
    } 
  }
  for(int i = 0; i < M; i++){
    long long d = ver[i][0];
    long long e = ver[i][1];
    long long f = ver[i][2];
    d = xdic[d];
    e = ydic[e];
    f = ydic[f];
    for(int j = e; j < f; j++){
      ver_dic[d][j] = 1;
    } 
  }  
  

  int x0,y0;
  for(int i = 0; i<len_x_tic;i++){
    if (x_tic[i] == 0){
      x0 = i+1;
      break;
    }
  }
  for(int i = 0; i<len_y_tic;i++){
    if (y_tic[i] == 0){
      y0 = i+1;
      break;
    }
  }
  
  int W = len_x_tic + 1;
  int H = len_y_tic + 1;
  
  gyaku_xdic[0] = -INF;
  gyaku_ydic[0] = -INF;
  gyaku_xdic[W] = INF;
  gyaku_ydic[H] = INF;
  
  d[y0][x0] = 1;
  
  q[0] = {y0,x0}; 
  q_len = 1;
  
  while (q_len > 0){
    long long x = q[q_len-1][0];
    long long y = q[q_len-1][1];
    area += calc_area(x,y);
    q_len -= 1;
    for(int i = 0; i < 4; i++){
      int nx = x + dx[i], ny = y + dy[i];
      if( 0<=nx && nx<W && 0<=ny && ny<H){
        if (is_connected(x,y,dx[i],dy[i])){
          if (nx == 0 || ny == 0 || nx == W-1 || ny == H-1){
            cout << "INF" << endl;
            exit(0);
          }
          if (d[ny][nx] == 0){
            d[ny][nx] = 1;
            q[q_len] = {nx,ny};
            q_len += 1;
          }
        }
      }
    }
  }
  
  cout << area << endl;
  exit(0);
}
