#include <bits/stdc++.h>
using namespace std;
const int nax = 3010;
int cx = 0, cy = 0;
vector<int> lx, ly;
long long area = 0;
int done[nax][nax], bx[nax][nax], by[nax][nax];
void dfs(int xi, int yi) {
  if (xi < 0 || yi < 0 || xi + 1 >= cx || yi + 1 >= cy) {
    cout << "INF" << endl;
    exit(0);
  }
  if (done[yi][xi]++) return;
  long long x0 = lx[xi], x1 = lx[xi + 1];
  long long y0 = ly[yi], y1 = ly[yi + 1];
  area += (x1 - x0) * (y1 - y0);
  if (!bx[yi][xi]) dfs(xi - 1, yi);
  if (!bx[yi][xi + 1]) dfs(xi + 1, yi);
  if (!by[yi][xi]) dfs(xi, yi - 1);
  if (!by[yi + 1][xi]) dfs(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;
    }
  }
  dfs(mx[0], my[0]);
  cout << area << endl;
}
