#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  long long A[1010], B[1010], C[1010], D[1010], E[1010], F[1010];
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i];
  for (int i = 0; i < M; i++) cin >> D[i] >> E[i] >> F[i];
  set<long long> x, y;
  x.insert(-1e15);
  x.insert(1e15);
  y.insert(-1e15);
  y.insert(1e15);
  for (int i = 0; i < N; i++) {
    x.insert(A[i]);
    x.insert(B[i]);
    y.insert(C[i]);
  }
  for (int i = 0; i < M; i++) {
    x.insert(D[i]);
    y.insert(E[i]);
    y.insert(F[i]);
  }
  map<long long, int> Mx, My;
  int idx = 0;
  long long xx[3010], yy[3010];
  for (auto it = x.begin(); it != x.end(); it++) {
    Mx[*it] = idx;
    xx[idx] = *it;
    idx++;
  }
  int Lx = idx;
  idx = 0;
  for (auto it = y.begin(); it != y.end(); it++) {
    My[*it] = idx;
    yy[idx] = *it;
    idx++;
  }
  int Ly = idx;
  long long Dx[3010] = {};
  long long Dy[3010] = {};
  for (int i = 0; i < Lx - 1; i++) Dx[i] = xx[i + 1] - xx[i];
  for (int i = 0; i < Ly - 1; i++) Dy[i] = yy[i + 1] - yy[i];
  bool right[3010][3010] = {};
  bool left[3010][3010] = {};
  bool down[3010][3010] = {};
  bool up[3010][3010] = {};
  for (int i = 0; i < N; i++) {
    int a = Mx[A[i]];
    int b = Mx[B[i]];
    int c = My[C[i]];
    for (int i = a; i < b; i++) {
      up[i][c - 1] = true;
      down[i][c] = true;
    }
  }
  for (int i = 0; i < M; i++) {
    int d = Mx[D[i]];
    int e = My[E[i]];
    int f = My[F[i]];
    for (int i = e; i < f; i++) {
      left[d][i] = true;
      right[d - 1][i] = true;
    }
  }
  bool can[3010][3010] = {};
  int Gx = lower_bound(xx, xx + Lx, 0LL) - xx;
  Gx--;
  int Gy = lower_bound(yy, yy + Ly, 0LL) - yy;
  Gy--;
  queue<pair<int, int>> que;
  que.push(make_pair(Gx, Gy));
  can[Gx][Gy] = true;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    int x = p.first;
    int y = p.second;
    for (int i = 0; i < 4; i++) {
      if (i == 0 && right[x][y]) continue;
      if (i == 1 && up[x][y]) continue;
      if (i == 2 && left[x][y]) continue;
      if (i == 3 && down[x][y]) continue;
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (can[nx][ny] || nx < 0 || nx >= Lx || ny < 0 || ny >= Ly) continue;
      que.push(make_pair(nx, ny));
      can[nx][ny] = true;
    }
  }
  long long ans = 0LL;
  for (int i = 0; i < Lx; i++) {
    for (int j = 0; j < Ly; j++) {
      if (!can[i][j]) continue;
      if (Dx[i] > 10000000000 || Dy[i] > 10000000000) {
        cout << "INF" << endl;
        return 0;
      }
      ans += Dx[i] * Dy[i];
    }
  }
  cout << ans << endl;
}
