#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005, maxm = 3005, maxp = 9000005, INF = 0x7FFFFFFF;
struct data {
  int L, R, pos;
} cowx[maxn], cowy[maxn];
struct disc {
  int num, kind, No;
} disx[maxm], disy[maxm];
int n, m, px, py, r, c, sx, sy, p, com[maxp], No[maxm][maxm];
bool row[maxm][maxm], col[maxm][maxm];
bool cmp(disc A, disc B) { return A.num < B.num; }
int finds(int A) { return com[A] < 0 ? A : com[A] = finds(com[A]); }
void connect(int A, int B) {
  int x = finds(A), y = finds(B);
  if (x == y) return;
  if (com[x] < com[y])
    com[x] += com[y], com[y] = x;
  else
    com[y] += com[x], com[x] = y;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &cowx[i].L, &cowx[i].R, &cowx[i].pos);
    py++;
    disy[py].num = cowx[i].L;
    disy[py].No = i;
    disy[py].kind = 1;
    py++;
    disy[py].num = cowx[i].R;
    disy[py].No = i;
    disy[py].kind = 2;
    px++;
    disx[px].num = cowx[i].pos;
    disx[px].No = i;
    disx[px].kind = 3;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &cowy[i].pos, &cowy[i].L, &cowy[i].R);
    py++;
    disy[py].num = cowy[i].pos;
    disy[py].No = i;
    disy[py].kind = 4;
    px++;
    disx[px].num = cowy[i].L;
    disx[px].No = i;
    disx[px].kind = 5;
    px++;
    disx[px].num = cowy[i].R;
    disx[px].No = i;
    disx[px].kind = 6;
  }
  disx[++px].kind = 7;
  disy[++py].kind = 8;
  sort(disx + 1, disx + 1 + px, cmp);
  sort(disy + 1, disy + 1 + py, cmp);
  disx[0].num = disy[0].num = INF;
  for (int i = 1; i <= px; i++) {
    if (disx[i].num != disx[i - 1].num) r++;
    if (disx[i].kind == 3)
      cowx[disx[i].No].pos = r;
    else if (disx[i].kind == 5)
      cowy[disx[i].No].L = r;
    else if (disx[i].kind == 6)
      cowy[disx[i].No].R = r;
    else
      sx = r;
  }
  for (int i = 1; i <= py; i++) {
    if (disy[i].num != disy[i - 1].num) c++;
    if (disy[i].kind == 1)
      cowx[disy[i].No].L = c;
    else if (disy[i].kind == 2)
      cowx[disy[i].No].R = c;
    else if (disy[i].kind == 4)
      cowy[disy[i].No].pos = c;
    else
      sy = c;
  }
  for (int i = 1; i <= n; i++)
    for (int j = cowx[i].L; j <= cowx[i].R; j++) row[cowx[i].pos][j] = true;
  for (int i = 1; i <= m; i++)
    for (int j = cowy[i].L; j <= cowy[i].R; j++) col[j][cowy[i].pos] = true;
  for (int i = 1; i < r; i++)
    for (int j = 1; j < c; j++) No[i][j] = ++p;
  memset(com, -1, sizeof(com));
  for (int i = 1; i <= r; i++)
    for (int j = 1; j < c; j++)
      if (!row[i][j] || !row[i][j + 1]) connect(No[i - 1][j], No[i][j]);
  for (int j = 1; j <= c; j++)
    for (int i = 1; i < r; i++)
      if (!col[i][j] || !col[i + 1][j]) connect(No[i][j - 1], No[i][j]);
  int x = finds(No[sx][sy]), y = finds(0);
  if (x != y)
    printf("%d\n", -com[x]);
  else
    puts("INF");
  return 0;
}
