#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000;
const int MAX_M = 1000;
const int MAX_XN = MAX_N * 2 + MAX_M + 1;
const int MAX_YN = MAX_M * 2 + MAX_N + 1;
const int dxs[] = {0, 1, 0, -1}, dys[] = {1, 0, -1, 0};
int as[MAX_N], bs[MAX_N], cs[MAX_N];
int ds[MAX_M], es[MAX_M], fs[MAX_M];
int xs[MAX_XN], ys[MAX_YN];
bool ls[MAX_XN][MAX_YN][4], used[MAX_XN][MAX_YN];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int xn = 0, yn = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", as + i, bs + i, cs + i);
    xs[xn++] = as[i], xs[xn++] = bs[i], ys[yn++] = cs[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", ds + i, es + i, fs + i);
    xs[xn++] = ds[i], ys[yn++] = es[i], ys[yn++] = fs[i];
  }
  xs[xn++] = ys[yn++] = 0;
  sort(xs, xs + xn);
  sort(ys, ys + yn);
  xn = unique(xs, xs + xn) - xs;
  yn = unique(ys, ys + yn) - ys;
  for (int i = 0; i < n; i++) {
    int x0 = lower_bound(xs, xs + xn, as[i]) - xs;
    int x1 = lower_bound(xs, xs + xn, bs[i]) - xs;
    int y = lower_bound(ys, ys + yn, cs[i]) - ys;
    for (int x = x0; x < x1; x++) {
      ls[x][y][2] = true;
      if (y > 0) ls[x][y - 1][0] = true;
    }
  }
  for (int i = 0; i < m; i++) {
    int x = lower_bound(xs, xs + xn, ds[i]) - xs;
    int y0 = lower_bound(ys, ys + yn, es[i]) - ys;
    int y1 = lower_bound(ys, ys + yn, fs[i]) - ys;
    for (int y = y0; y < y1; y++) {
      ls[x][y][3] = true;
      if (x > 0) ls[x - 1][y][1] = true;
    }
  }
  int sx = lower_bound(xs, xs + xn, 0) - xs;
  int sy = lower_bound(ys, ys + yn, 0) - ys;
  used[sx][sy] = true;
  int s = 1;
  queue<pair<int, int> > q;
  q.push(pair<int, int>(sx, sy));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    int ux = u.first, uy = u.second;
    for (int di = 0; di < 4; di++)
      if (!ls[ux][uy][di]) {
        int vx = ux + dxs[di], vy = uy + dys[di];
        if (vx < 0 || vx >= xn || vy < 0 || vy >= yn) {
          puts("INF");
          return 0;
        }
        if (!used[vx][vy]) {
          used[vx][vy] = true;
          s++;
          q.push(pair<int, int>(vx, vy));
        }
      }
  }
  printf("%d\n", s);
  return 0;
}
