#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
int n, m;
map<long, int> mx;
map<long, int> my;
int h, w;
int a[1000];
int b[1000];
int c[1000];
int d[1000];
int e[1000];
int f[1000];
long vx[8001];
long vy[8001];
bool field[8001][8001];
bool used[8001][8001];
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
long rec(int x, int y) {
  if (used[x][y]) return 0;
  used[x][y] = true;
  if (field[x][y]) return 0;
  if (x == 0 || x == h - 1 || y == 0 || y == w - 1) return -1;
  long sum;
  if (x % 2 == 1 || y % 2 == 1) {
    sum = 0;
  } else {
    sum = (vx[x + 1] - vx[x - 1]) * (vy[y + 1] - vy[y - 1]);
  }
  cerr << sum << endl;
  for (int k = 0; k < 4; ++k) {
    int nx = x + dx[k];
    int ny = y + dy[k];
    long res = rec(nx, ny);
    if (res < 0) return -1;
    sum += res;
  }
  return sum;
}
string solve() {
  for (int i = 0; i < n; ++i) {
    int x1 = mx[a[i]];
    int x2 = mx[b[i]];
    int y = my[c[i]];
    for (int k = x1; k <= x2; ++k) {
      field[k][y] = true;
    }
  }
  for (int i = 0; i < m; ++i) {
    int x = mx[d[i]];
    int y1 = my[e[i]];
    int y2 = my[f[i]];
    for (int k = y1; k <= y2; ++k) {
      field[x][k] = true;
    }
  }
  h = 2 * mx.size() + 1;
  w = 2 * my.size() + 1;
  int sx = mx.lower_bound(0)->second - 1;
  int sy = my.lower_bound(0)->second - 1;
  long res = rec(sx, sy);
  return res < 0 ? "INF" : to_string(res);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    mx[a[i]];
    mx[b[i]];
    my[c[i]];
  }
  for (int i = 0; i < m; ++i) {
    cin >> d[i] >> e[i] >> f[i];
    mx[d[i]];
    my[e[i]];
    my[f[i]];
  }
  int cnt = 1;
  for (auto&& [p, q] : mx) {
    q = cnt;
    vx[cnt] = p;
    cnt += 2;
  }
  cnt = 1;
  for (auto&& [p, q] : my) {
    q = cnt;
    vy[cnt] = p;
    cnt += 2;
  }
  cout << solve() << endl;
}
