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

const int nax = 3010;
int cx = 0, cy = 0;
vector<int> lx, ly;
ll area = 0;
int done[nax][nax], bx[nax][nax], by[nax][nax];

void bfs(int sx, int sy) {
  queue<pair<int,int>> q;
  q.emplace(sx,sy);
  while (q.size()) {
    auto [xi,yi] = q.front();
    q.pop();
    if (xi < 0 || yi < 0 || xi+1 >= cx || yi+1 >= cy) {
      cout << "INF" << endl;
      exit(0);
    }
    if (done[yi][xi]++) continue;
    ll x0 = lx[xi], x1 = lx[xi+1];
    ll y0 = ly[yi], y1 = ly[yi+1];
    area += (x1-x0)*(y1-y0);
    if (!bx[yi][xi])
      q.emplace(xi-1,yi);
    if (!bx[yi][xi+1])
      q.emplace(xi+1,yi);
    if (!by[yi][xi])
      q.emplace(xi,yi-1);
    if (!by[yi+1][xi])
      q.emplace(xi,yi+1);
  }
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int nv, nh;
  cin >> nv >> nh;
  map<int,int> mx, my;
  mx[0],my[0];
  vector<array<int,3>> hori, vert;
  for (int i = 0; i < nv; i++) {
    int sy, ey, x;
    cin >> sy >> ey >> x;
    vert.push_back({sy, ey, x});
    mx[x];
    my[sy], my[ey];
  }
  for (int i = 0; i < nh; i++) {
    int y, sx, ex;
    cin >> y >> sx >> ex;
    hori.push_back({y, sx, ex});
    mx[sx], mx[ex];
    my[y];
  }
  for (auto&[x,c] : mx) {
    c = cx++;
    lx.push_back(x);
  }
  for (auto&[y,c] : my) {
    c = cy++;
    ly.push_back(y);
  }
  for (auto [sy, ey, x] : vert) {
    int ei = my[ey];
    int xi = mx[x];
    for (int i = my[sy]; i < ei; i++) {
      bx[i][xi] = 1;
    }
  }
  for (auto [y, sx, ex] : hori) {
    int ei = mx[ex];
    int yi = my[y];
    for (int i = mx[sx]; i < ei; i++) {
      by[yi][i] = 1;
    }
  }

  /*for (int i = 0; i < cy; i++) {
    for (int j = 0; j < cx; j++)
      cout << bx[i][j] << ' ' << by[i][j] << "   ";
  cout << endl;
  }*/
  bfs(mx[0],my[0]);
  cout << area << endl;
}
