#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  set<int> X, Y;
  map<int, vector<pair<int, int>>> V;
  for (int i = 0; i < N; i++){
    int A, B, C;
    cin >> A >> B >> C;
    Y.insert(A);
    Y.insert(B);
    X.insert(C);
    V[C].push_back(make_pair(A, B));
  }
  map<int, vector<pair<int, int>>> H;
  for (int i = 0; i < M; i++){
    int D, E, F;
    cin >> D >> E >> F;
    Y.insert(D);
    X.insert(E);
    X.insert(F);
    H[D].push_back(make_pair(E, F));
  }
  //compress
  int Xcnt = X.size();
  int Ycnt = Y.size();
  vector<long long> Xc;
  for (int x : X){
    Xc.push_back(x);
  }
  vector<long long> Yc;
  for (int y : Y){
    Yc.push_back(y);
  }
  map<int, int> Xp;
  for (int i = 0; i < Xcnt; i++){
    Xp[Xc[i]] = i;
  }
  map<int, int> Yp;
  for (int i = 0; i < Ycnt; i++){
    Yp[Yc[i]] = i;
  }
  map<int, vector<pair<int, int>>> V2;
  for (auto P : V){
    int x = P.first;
    int x2 = Xp[x];
    vector<pair<int, int>> y = P.second;
    sort(y.begin(), y.end());
    for (int i = 0; i < y.size(); i++){
      y[i].first = Yp[y[i].first];
      y[i].second = Yp[y[i].second];
    }
    vector<pair<int, int>> y2;
    for (int i = 0; i < y.size(); i++){
      if (i == 0){
        y2.push_back(y[i]);
      } else if (y[i - 1].second < y[i].first){
        y2.push_back(y[i]);
      } else {
        y2.back().second = max(y2.back().second, y[i].second);
      }
    }
    V2[x2] = y2;
  }
  map<int, vector<pair<int, int>>> H2;
  for (auto P : H){
    int y = P.first;
    int y2 = Yp[y];
    vector<pair<int, int>> x = P.second;
    sort(x.begin(), x.end());
    for (int i = 0; i < x.size(); i++){
      x[i].first = Xp[x[i].first];
      x[i].second = Xp[x[i].second];
    }
    vector<pair<int, int>> x2;
    for (int i = 0; i < x.size(); i++){
      if (i == 0){
        x2.push_back(x[i]);
      } else if (x[i - 1].second < x[i].first){
        x2.push_back(x[i]);
      } else {
        x2.back().second = max(x2.back().second, x[i].second);
      }
    }
    H2[y2] = x2;
  }
  //calculate area
  vector<vector<long long>> area(Ycnt + 1, vector<long long>(Xcnt + 1, 0));
  for (int i = 1; i < Ycnt; i++){
    for (int j = 1; j < Xcnt; j++){
      area[i][j] = (Yc[i] - Yc[i - 1]) * (Xc[j] - Xc[j - 1]);
    }
  }
  //lines
  int start_y = lower_bound(Yc.begin(), Yc.end(), 0) - Yc.begin();
  int start_x = lower_bound(Xc.begin(), Xc.end(), 0) - Xc.begin();
  vector<vector<bool>> L(Ycnt + 1, vector<bool>(Xcnt + 1, true));
  for (int i = 0; i <= Ycnt; i++){
    L[i][0] = false;
  }
  vector<vector<bool>> R(Ycnt + 1, vector<bool>(Xcnt + 1, true));
  for (int i = 0; i <= Ycnt; i++){
    R[i][Xcnt] = false;
  }
  for (auto P : V2){
    int x = P.first;
    for (auto Q : P.second){
      int y1 = Q.first;
      int y2 = Q.second;
      for (int i = y1 + 1; i <= y2; i++){
        L[i][x + 1] = false;
        R[i][x] = false;
      }
    }
  }
  vector<vector<bool>> U(Ycnt + 1, vector<bool>(Xcnt + 1, true));
  for (int i = 0; i <= Xcnt; i++){
    U[0][i] = false;
  }
  vector<vector<bool>> D(Ycnt + 1, vector<bool>(Xcnt + 1, true));
  for (int i = 0; i <= Xcnt; i++){
    D[Ycnt][i] = false;
  }
  for (auto P : H2){
    int y = P.first;
    for (auto Q : P.second){
      int x1 = Q.first;
      int x2 = Q.second;
      for (int i = x1 + 1; i <= x2; i++){
        U[y + 1][i] = false;
        D[y][i] = false;
      }
    }
  }
  //BFS
  vector<vector<bool>> used(Ycnt + 1, vector<bool>(Xcnt + 1, false));
  used[start_y][start_x] = true;
  queue<pair<int, int>> Q;
  Q.push(make_pair(start_y, start_x));
  while (!Q.empty()){
    int y = Q.front().first;
    int x = Q.front().second;
    Q.pop();
    if (U[y][x]){
      if (!used[y - 1][x]){
        used[y - 1][x] = true;
        Q.push(make_pair(y - 1, x));
      }
    }
    if (D[y][x]){
      if (!used[y + 1][x]){
        used[y + 1][x] = true;
        Q.push(make_pair(y + 1, x));
      }
    }
    if (L[y][x]){
      if (!used[y][x - 1]){
        used[y][x - 1] = true;
        Q.push(make_pair(y, x - 1));
      }
    }
    if (R[y][x]){
      if (!used[y][x + 1]){
        used[y][x + 1] = true;
        Q.push(make_pair(y, x + 1));
      }
    }
  }
  //calculate total area
  bool inf = false;
  long long total = 0;
  for (int i = 0; i <= Ycnt; i++){
    for (int j = 0; j <= Xcnt; j++){
      if (used[i][j]){
        if (i == 0 || i == Ycnt || j == 0 || j == Xcnt){
          inf = true;
        } else {
          total += area[i][j];
        }
      }
    }
  }
  if (inf){
    cout << "INF" << endl;
  } else {
    cout << total << endl;
  }
}

Measured memory_bytes: 81360