#include <bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
struct Problem {
  UL W, H;
  pair<LL, pair<LL, LL>> V[1001];
  pair<LL, pair<LL, LL>> U[1001];
  bool F[1002][1002] = {};
  bool E[1002][1002][4] = {};
  pair<int, int> d[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  LL X[1001], Y[1001];
  UL rBinSc(LL* A, LL p, UL l, UL r) {
    while (l + 1 < r) {
      UL m = (l + r) >> 1;
      if (A[m - 1] <= p)
        l = m;
      else
        r = m;
    }
    return l;
  }
  void Solve() {
    scanf("%d%d", &W, &H);
    for (UL i = 0; i < (W); i++) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      V[i] = {c, {a, b}};
    }
    for (UL i = 0; i < (H); i++) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      U[i] = {a, {b, c}};
    }
    sort(V, V + W);
    sort(U, U + H);
    for (UL i = 0; i < (W); i++) X[i] = V[i].first;
    for (UL i = 0; i < (H); i++) Y[i] = U[i].first;
    for (UL i = 0; i < (W); i++) {
      UL l = rBinSc(Y, V[i].second.first - 1, 0, H + 1);
      UL r = rBinSc(Y, V[i].second.second, 0, H + 1);
      for (UL j = l; j + 1 < r; j++) {
        E[i + 1][j + 1][0] = true;
        E[i][j + 1][1] = true;
      }
    }
    for (UL i = 0; i < (H); i++) {
      UL l = rBinSc(X, U[i].second.first - 1, 0, W + 1);
      UL r = rBinSc(X, U[i].second.second, 0, W + 1);
      for (UL j = l; j + 1 < r; j++) {
        E[j + 1][i + 1][2] = true;
        E[j + 1][i][3] = true;
      }
    }
    for (UL i = 0; i < (W + 1); i++) E[i][0][2] = E[i][H][3] = true;
    for (UL i = 0; i < (H + 1); i++) E[0][i][0] = E[W][i][1] = true;
    stack<pair<int, int>> Q;
    {
      UL sx = rBinSc(X, 0, 0, W + 1);
      UL sy = rBinSc(Y, 0, 0, H + 1);
      Q.push(make_pair((int)sx, (int)sy));
    }
    while (Q.size()) {
      int x = Q.top().first;
      int y = Q.top().second;
      Q.pop();
      if (F[x][y]) continue;
      F[x][y] = true;
      for (UL j = 0; j < (4); j++) {
        if (!E[x][y][j]) Q.push(make_pair(x + d[j].first, y + d[j].second));
      }
    }
    bool inf = false;
    for (UL i = 0; i < (W); i++) {
      if (F[i][0] || F[i][H]) inf = true;
    }
    for (UL i = 0; i < (H); i++) {
      if (F[0][i] || F[W][i]) inf = true;
    }
    LL S = 0;
    for (UL x = 0; x < (W - 1); x++)
      for (UL y = 0; y < (H - 1); y++)
        if (F[x + 1][y + 1]) S += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y]);
    if (inf)
      printf("INF\n");
    else
      printf("%lld\n", S);
  }
};
int main() {
  unique_ptr<Problem> p(new Problem());
  p->Solve();
  return 0;
}
