#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(const T& x) {
  cout << x << endl;
}
template <class T, class... A>
void print(const T& first, const A&... rest) {
  cout << first << " ";
  print(rest...);
}
struct PreMain {
  PreMain() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} premain;
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<int> size;
  UnionFind(int N) : par(N), rank(N), size(N) {
    for (int i = 0; i < N; i++) {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    if (rank[rx] < rank[ry]) swap(rx, ry);
    if (rank[rx] == rank[ry]) ++rank[rx];
    par[ry] = rx;
    size[rx] += size[ry];
    size[ry] = 0;
  }
  bool same(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    return rx == ry;
  }
  int get_size(int x) {
    int rx = find(x);
    return size[rx];
  }
};
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N), C(N);
  for (int(i) = 0; (i) < (int)(N); ++(i)) cin >> A[i] >> B[i] >> C[i];
  vector<int> D(M), E(M), F(M);
  for (int(i) = 0; (i) < (int)(M); ++(i)) cin >> D[i] >> E[i] >> F[i];
  vector<int> Xs{(int)-2e9, 0, (int)2e9};
  vector<int> Ys{(int)-2e9, 0, (int)2e9};
  for (int(i) = 0; (i) < (int)(N); ++(i)) {
    Xs.emplace_back(A[i]);
    Xs.emplace_back(B[i]);
    Ys.emplace_back(C[i]);
  }
  for (int(i) = 0; (i) < (int)(M); ++(i)) {
    Xs.emplace_back(D[i]);
    Ys.emplace_back(E[i]);
    Ys.emplace_back(F[i]);
  }
  sort(Xs.begin(), Xs.end());
  Xs.erase(unique(Xs.begin(), Xs.end()), Xs.end());
  sort(Ys.begin(), Ys.end());
  Ys.erase(unique(Ys.begin(), Ys.end()), Ys.end());
  int H = Xs.size();
  int W = Ys.size();
  vector<vector<int>> imos_x(H, vector<int>(W, 0));
  vector<vector<int>> imos_y(H, vector<int>(W, 0));
  for (int(i) = 0; (i) < (int)(N); ++(i)) {
    A[i] = distance(Xs.begin(), lower_bound(Xs.begin(), Xs.end(), A[i]));
    B[i] = distance(Xs.begin(), lower_bound(Xs.begin(), Xs.end(), B[i]));
    C[i] = distance(Ys.begin(), lower_bound(Ys.begin(), Ys.end(), C[i]));
    imos_x[A[i]][C[i]]++;
    imos_x[B[i]][C[i]]--;
  }
  for (int(i) = 0; (i) < (int)(M); ++(i)) {
    D[i] = distance(Xs.begin(), lower_bound(Xs.begin(), Xs.end(), D[i]));
    E[i] = distance(Ys.begin(), lower_bound(Ys.begin(), Ys.end(), E[i]));
    F[i] = distance(Ys.begin(), lower_bound(Ys.begin(), Ys.end(), F[i]));
    imos_y[D[i]][E[i]]++;
    imos_y[D[i]][F[i]]--;
  }
  UnionFind uf(H * W);
  for (int(i) = 0; (i) < (int)(H); ++(i))
    for (int(j) = 0; (j) < (int)(W); ++(j)) {
      if (i > 0) imos_x[i][j] += imos_x[i - 1][j];
      if (j > 0) imos_y[i][j] += imos_y[i][j - 1];
      if (i > 0 && imos_y[i][j] == 0) uf.unite(i * W + j, (i - 1) * W + j);
      if (j > 0 && imos_x[i][j] == 0) uf.unite(i * W + j, i * W + (j - 1));
    }
  int sx = distance(Xs.begin(), lower_bound(Xs.begin(), Xs.end(), 0));
  int sy = distance(Ys.begin(), lower_bound(Ys.begin(), Ys.end(), 0));
  if (uf.same(sx * H + sy, 0)) {
    print("INF");
    return 0;
  }
  long long ans = 0;
  for (int(i) = 0; (i) < (int)(H - 1); ++(i))
    for (int(j) = 0; (j) < (int)(W - 1); ++(j)) {
      if (uf.same(sx * W + sy, i * W + j)) {
        ans += (long long)(Xs[i + 1] - Xs[i]) * (Ys[j + 1] - Ys[j]);
      }
    }
  print(ans);
  return 0;
}
