#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
const int DX[4] = {0, 0, +1, -1};
const int DY[4] = {+1, -1, 0, 0};
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N), C(N), D(M), E(M), F(M);
  vector<int> X, Y;
  X.push_back(0);
  Y.push_back(0);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i];
    X.push_back(A[i]);
    X.push_back(B[i]);
    Y.push_back(C[i]);
  }
  for (int i = 0; i < M; i++) {
    cin >> D[i] >> E[i] >> F[i];
    X.push_back(D[i]);
    Y.push_back(E[i]);
    Y.push_back(F[i]);
  }
  sort(begin(X), end(X));
  X.erase(unique(begin(X), end(X)), end(X));
  sort(begin(Y), end(Y));
  Y.erase(unique(begin(Y), end(Y)), end(Y));
  int zero_x = 2 * (lower_bound(begin(X), end(X), 0) - begin(X));
  int zero_y = 2 * (lower_bound(begin(Y), end(Y), 0) - begin(Y));
  for (int i = 0; i < N; i++) {
    A[i] = 2 * (lower_bound(begin(X), end(X), A[i]) - begin(X));
    B[i] = 2 * (lower_bound(begin(X), end(X), B[i]) - begin(X));
    C[i] = 2 * (lower_bound(begin(Y), end(Y), C[i]) - begin(Y));
  }
  for (int i = 0; i < M; i++) {
    D[i] = 2 * (lower_bound(begin(X), end(X), D[i]) - begin(X));
    E[i] = 2 * (lower_bound(begin(Y), end(Y), E[i]) - begin(Y));
    F[i] = 2 * (lower_bound(begin(Y), end(Y), F[i]) - begin(Y));
  }
  vector<vector<bool>> visited(X.size() * 2 + 1,
                               vector<bool>(Y.size() * 2 + 1));
  for (int i = 0; i < N; i++) {
    for (int x = A[i]; x <= B[i]; x++) {
      visited[x][C[i]] = 1;
    }
  }
  for (int i = 0; i < M; i++) {
    for (int y = E[i]; y <= F[i]; y++) {
      visited[D[i]][y] = 1;
    }
  }
  stack<pair<int, int>> S;
  S.emplace(zero_x, zero_y);
  while (!S.empty()) {
    auto [x, y] = S.top();
    S.pop();
    if (visited[x][y]) continue;
    visited[x][y] = 1;
    if (x == 0 || x == X.size() * 2 || y == 0 || y == Y.size() * 2) {
      cout << "INF\n";
      return 0;
    }
    for (int i = 0; i < 4; i++) {
      int nx = x + DX[i];
      int ny = y + DY[i];
      if (0 <= nx && nx < X.size() * 2 + 1 && 0 <= ny &&
          ny < Y.size() * 2 + 1) {
        S.emplace(nx, ny);
      }
    }
  }
  Int ans = 0;
  for (int i = 0; i < X.size() - 1; i++) {
    for (int j = 0; j < Y.size() - 1; j++) {
      if (visited[i * 2 + 1][j * 2 + 1]) {
        ans += (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
