#include <bits/stdc++.h>
using namespace std;
struct P {
  double x, y;
  bool operator<(const P& t) const {
    return (x < t.x || (x == t.x && y < t.y));
  }
};
int N, M;
int A[1002], B[1002], C[1002];
int D[1002], E[1002], F[1002];
int dx[] = {-1, 0, 0, 1}, dy[] = {0, -1, 1, 0};
bool ok(P s, P t) {
  if (s.y == t.y) {
    for (int i = 0; i < M; i++) {
      if (E[i] < s.y && s.y < F[i]) {
        if ((s.x < D[i] && D[i] < t.x) || (t.x < D[i] && D[i] < s.x)) {
          return false;
        }
      }
    }
  } else {
    for (int i = 0; i < M; i++) {
      if (A[i] < s.x && s.x < B[i]) {
        if ((s.y < C[i] && C[i] < t.y) || (t.y < C[i] && C[i] < s.y)) {
          return false;
        }
      }
    }
  }
  return true;
}
void solve() {
  set<P> used;
  queue<P> q;
  q.push(P{-0.5, -0.5});
  q.push(P{-0.5, 0.5});
  q.push(P{0.5, -0.5});
  q.push(P{0.5, 0.5});
  int ans = 0;
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    if (used.count(p) > 0) {
      continue;
    }
    used.insert(p);
    for (int i = 0; i < 4; i++) {
      P np = P{p.x + dx[i], p.y + dy[i]};
      if (ok(p, np) && used.count(np) == 0) {
        ans++;
        q.push(np);
      }
    }
    if (ans >= 100000) break;
  }
  if (ans == 100000) {
    puts("INF");
  } else {
    printf("%d\n", ans);
  }
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", A + i, B + i, C + i);
  }
  for (int i = 0; i < M; i++) {
    scanf("%d %d %d", D + i, E + i, F + i);
  }
  solve();
}
